Reputation: 7119
I am performing two parallel requests to my web service using WebClient and multithreading them with ThreadPool. However, I'm having an issue in one of the threads where I get this WebException:
The server committed a protocol violation. Section=ResponseStatusLine
I did some research and found that it could be an unsafe header validation issue, but the requests work fine in single thread mode.
So just to clarify, I am firing off two threads. One is doing a GET of a URI, and one is doing a POST of some data to a URI. The first GET works fine, but the POST fails with the WebException above.
Any ideas? Thanks.
Upvotes: 2
Views: 3248
Reputation: 2382
Adding following to web.config solved my problem.
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
Upvotes: 1
Reputation: 7119
I fixed my issue by adding
request.ServicePoint.Expect100Continue = false;
before making my POST call. What was happening according to wireshark was my HttpWebRequest was expecting 100 continue, but getting 401 not authorized, but it was sending the data anyways after the server response, instead of sending an authorization header. It wasn't happening everytime, but this seems to fix it.
Upvotes: 1
Reputation: 60972
Note that instances of the WebClient class are not guaranteed to be thread-safe. Are you using one instance of WebClient across your threads, or does each thread have its own instance? It should be the latter.
Upvotes: 0