HttpWebRequest : Expect: 100-continue Header Problem

I used the HttpWebRequest to POST request using HTTP 1.1, i received the following HTTP header "Expect: 100-Continue". After few time to play with google, i found a treasure article at Phil Haack site.

Here is solution :
System.Net.ServicePointManager class has a static property named Expect100Continue. Setting this to false will stop the header "Expect: 100-Continue" from being sent.

You may see code snippet below about how to implement it.
// create web request
HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create("http://something");
webRequest.Method = "POST";
webRequest.ServicePoint.Expect100Continue = false;

// post data
requestStream = webRequest.GetRequestStream();
StreamWriter requestWriter = new StreamWriter(requestStream);

//wait for server response
HttpWebResponse response = (HttpWebResponse) webRequest.GetResponse();

0 nhận xét:


Coding experience share Copyright © 2010 | Designed by Ipietoon for Free Blogger Template