What is the best way to set expect100continue when using WebClient(C#.NET). I have this code below, I still see 100 continue in the header. Stupid apache still complains with 505 error.
string url = "http://aaaa.com";
ServicePointManager.Expect100Continue = false;
WebClient service = new WebClient();
service.Credentials = new NetworkCredential("username", "password");
service.Headers.Add("Content-Type","text/xml");
service.UploadStringCompleted += (sender, e) => CompleteCallback(BuildResponse(e));
service.UploadStringAsync(new Uri(url), "POST", query);
Note: If I put the above in a console app and let it run - then I do not see the headers in fiddler. But, my code is embedded in a user library which is loaded by a WPF app. So, Is there more to Expect100Continue in terms of thread, initialization, etc. Now, I think it is more of my code issue.
Try to create the WebClient instanse after you change Expect100Continue to false. Or use a
Webrequest
instead of aWebClient
You need to set the
Expect100Continue
property on theServicePoint
used for the URI you're accessing:The only way to do this is to create an override.
This works perfect.
One of my below approach also worked,
In my constructor of class (service calling), you can set
System.Net.ServicePointManager.Expect100Continue = false;
and then I have created BasicHttpBinding object and continued, it executed successfully.