HttpWebRequest的基础连接被关闭 [英] HttpWebRequest the underlying connection was closed
问题描述
我使用的HttpWebRequest
到 POST
通过Web服务的字节数组图片,图片大小是一样的东西字节[4096]
代码:
的HttpWebRequest的WebRequest =(HttpWebRequest的)WebRequest.Create(wsHost);
webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding,gzip的,放气);
webRequest.Headers.Add(HttpRequestHeader.KeepAlive,真);
我得到一个错误:
<预类= 郎无prettyprint-覆盖>
基础连接已关闭。这是预计将保持活动状态的连接被服务器
难道是服务器的问题,或者关闭我张贴的问题?
这可能是大量的东西。你可以连接到另外的服务器?
如果是这样,请尝试关闭预计100继续(你让你的文章之前)通过
System.Net.ServicePointManager.Expect100Continue = FALSE;
根据HTTP 1.1协议,当这头发送后,形式数据不与初始请求发送。相反,该标头被发送到响应100(续)如果正确实现Web服务器。然而,并非所有的Web服务器正确处理这个问题,包括服务器到我试图发布数据。
块引用>
通过的http://haacked.com/archive/2004/05/15/http-网络请求期望-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;
I am using
HttpWebRequest
toPOST
a byte array picture through web services, the picture size is something likebyte[4096]
Code:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(wsHost); webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); webRequest.Headers.Add(HttpRequestHeader.KeepAlive, "true");
I get an error:
The underlying connection was closed. A connection that was expected to be kept alive was closed by the server
Is it the server problem, or my posting problem?
解决方案It could be a large number of things. Can you connect to the server otherwise?
If so, try turning off Expected 100 Continue (before you make your POST) via
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.
via http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx
If that doesn't work another resource: http://geekswithblogs.net/Denis/archive/2005/08/16/50365.aspx suggests that many have solved by crafting their requests as HTTP 1.0 requests:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(wsHost); webRequest.KeepAlive = false; webRequest.ProtocolVersion=HttpVersion.Version10;
这篇关于HttpWebRequest的基础连接被关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!