HTTP 遠端伺服器傳回一個錯誤: (500) 內部伺服器錯誤。

A first chance exception of type 'System.Net.WebException' occurred in Syste

遠端伺服器傳回一個錯誤: (500) 內部伺服器錯誤。

HTTP傳送文件時出現500錯誤

解決方案將 接收端 context.Response.ContentType = "text/plain";一段去掉就好了(測通后,後續再加上 測試時又正常)

請求端 request.ContentType = "multipart/form-data" 這個換掉后 接收端Files.Count=0 收不到文件

 HttpWebRequest request = (WebRequest.Create(url) as HttpWebRequest);

  CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = "POST";
request.Timeout = 300000;
string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;

 接收端 context.Response.ContentType = "text/plain";

public class HTTPHandler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        if (context.Request.Files.Count > 0)

猜你喜欢

转载自blog.csdn.net/losedguest/article/details/81906695