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