2012-11-02 82 views
4

我使用HttpWebRequestPOST通过Web服务的字节数组图片,图片大小是一样的东西byte[4096]HttpWebRequest的基础连接被关闭

代码:

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 

是服务器问题还是我的发布问题?

+0

..当你设置'webRequest.KeepAlive = false;'会发生什么? –

+0

我将其更改为false。错误仍然相同。事情是这个帖子没有登录Fiddler。 –

+0

我假设你已经调试过,发现'wsHost'实际上是一个你发布的有效URL? –

回答

6

它可能是很多事情。你可以连接到服务器吗?

如果是这样,请尝试关闭预计100通过http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx

继续(你让你的POST)之前通过

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://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; 
+0

是的,我已关闭它。只有当字节数组很大时才会发生这种情况。 –

+0

也许你应该用你尝试过的所有不同的东西编辑你的初始文章?这个问题发生了一堆不同的原因,我希望不要继续暗示你已经尝试过的东西。 – JoshVarty

+0

我正在使用fiddler,它关闭了连接。 –

相关问题