views:

192

answers:

1

Hello everyone,

I have a custom Http Handler which manipulates HTTP POST and GET. I got the project working on a seperate isolated server now need to put it in production...

using (var client = new WebClient())
                {
                    client.Credentials = CredentialCache.DefaultCredentials;
                    client.UploadFile("serverlocation:port", fileToUpload);
                }

For some reason now when using client.UploadFile("", file); i.e. forcing the HTTP POST

System.Net.WebException: The remote server returned an error: (417) Expectation failed.

   at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)

What could this be? I know the code works, so what else? Maybe the server blocks HTTP POST requests?

I have tried adding:

ServicePointManager.Expect100Continue = false;

But have had no success though i'm not 100% sure where this code should before, I assume before i'm using the WebClient


Edit 0 :

I have just read the following:

Because of the presence of older implementations, the protocol allows ambiguous situations in which a client may send "Expect: 100- continue" without receiving either a 417 (Expectation Failed) status or a 100 (Continue) status. Therefore, when a client sends this header field to an origin server (possibly via a proxy) from which it has never seen a 100 (Continue) status, the client SHOULD NOT wait for an indefinite period before sending the request body.

I believe this request is going through a proxy, which may have something to do with the issue.

Edit 1:

Believe this problem has to be with 100-continue because, using fiddler to see exactly what my application is sending with WebClient.UploadFile shows this:

POST http://XXX.XXX.XXX.XXX:8091/file.myhandledextension HTTP/1.1
Content-Type: multipart/form-data; boundary=---------------------8ccd1eb03f78bc2
Host: XXX.XXX.XXX.XXX:8091
Content-Length: 4492
Expect: 100-continue

Despite having put that line: ServicePointManager.Expect100Continue = false; before the using statement. I don't think this line actually works.

A: 

I ended up solving this by putting the ServicePointManager.Expect100Continue = false; in the constructor for the calling WebClient class.

Then I used Fiddler to examine the POST request to ensure Expect: 100-continue was not in the request anymore.

baron