2012-11-02 87 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,它關閉了連接。 –

相關問題