views:

605

answers:

2

Hi, 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.

A: 

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.

Michael Petrotta
Each has it's own instance. I'm noticing interesting behavior with my server. When I run my django app through mod_python and apache I get the error, but not when I run the django development server. Hmm, maybe it's not an issue on the client side.
Max
A: 

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.

Max