我正在使用 HttpWebRequest
通过网络服务POST
字节数组图片,图片大小类似于 byte[4096]
代码:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(wsHost);
webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
webRequest.Headers.Add(HttpRequestHeader.KeepAlive, "true");
我得到一个错误:
The underlying connection was closed. A connection that was expected to be kept alive was closed by the server
是服务器的问题,还是我发帖的问题?
最佳答案
可能有很多东西。否则你能连接到服务器吗?
如果是这样,请尝试关闭 Expected 100 Continue(在您进行 POST 之前)通过
System.Net.ServicePointManager.Expect100Continue = false;
According to the HTTP 1.1 protocol, when this header is sent, the form data is not sent with the initial request. Instead, this header is sent to the web server which responds with 100 (Continue) if implemented correctly. However, not all web servers handle this correctly, including the server to which I am attempting to post data.
通过http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx
如果这不起作用另一个资源:http://geekswithblogs.net/Denis/archive/2005/08/16/50365.aspx表明许多人已经通过将请求构造为 HTTP 1.0 请求来解决问题:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(wsHost);
webRequest.KeepAlive = false;
webRequest.ProtocolVersion=HttpVersion.Version10;
关于c# - HttpWebRequest 底层连接被关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13188058/