Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with webclient: Expectation failed?
    text
    copied!<p>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...</p> <pre><code>using (var client = new WebClient()) { client.Credentials = CredentialCache.DefaultCredentials; client.UploadFile("serverlocation:port", fileToUpload); } </code></pre> <hr> <p>For some reason now when using <code>client.UploadFile("", file);</code> i.e. forcing the HTTP POST</p> <pre><code>System.Net.WebException: The remote server returned an error: (417) Expectation failed. at System.Net.WebClient.UploadFile(Uri address, String method, String fileName) </code></pre> <p>What could this be? I know the code works, so what else? Maybe the server blocks HTTP POST requests?</p> <p>I have tried adding: </p> <p><code>ServicePointManager.Expect100Continue = false;</code></p> <p>But have had no success though i'm not 100% sure where this code should before, I assume before i'm using the WebClient</p> <hr> <p><strong>Edit 0 :</strong></p> <p>I have just <a href="http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/d5d85e6d-b870-4057-82c8-49bf849c98f5" rel="nofollow noreferrer">read</a> the following: </p> <p><em>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.</em></p> <p>I believe this request is going through a proxy, which may have something to do with the issue.</p> <p><strong>Edit 1:</strong></p> <p>Believe this problem has to be with 100-continue because, using fiddler to see exactly what my application is sending with <code>WebClient.UploadFile</code> shows this:</p> <pre><code>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 </code></pre> <p>Despite having put that line: <code>ServicePointManager.Expect100Continue = false;</code> before the using statement. I don't think this line actually works.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload