最近在写服务器端web上传的接口。但一直报错,上传不上去,后来发现是在分隔符中出现的问题。
错误的写法:
var boundary = "---------------" + DateTime.Now.Ticks.ToString("x"); var beginBoundary = Encoding.UTF8.GetBytes("--" + boundary + " "); var endBoundary = Encoding.UTF8.GetBytes("--" + boundary + "-- ");
正确的写法:
var boundary = "---------------" + DateTime.Now.Ticks.ToString("x"); var beginBoundary = Encoding.UTF8.GetBytes(" --" + boundary + " "); var endBoundary = Encoding.UTF8.GetBytes(" --" + boundary + "-- ");
就是少了个回车换行,但差距就是那么大,哎