I have a schedule task that is making a webrequest. This was all working fine. However all of sudden i’m getting the following error log.
12/05/2010 20:21:17
Failure reading XML
System.Net.WebException: The remote server returned an error: (417) Expectation failed.
at System.Net.HttpWebRequest.GetResponse()
at DelegateImport.Update.UpdateLiveSite(String delegateId, String badgeId)
at DelegateImport.Rss.RssReader()
Here is the code making the web request
WebRequest request = WebRequest.Create (uri);
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.Timeout = 30000000;
Stream dataStream = request.GetRequestStream ();
dataStream.Write (byteArray, 0, byteArray.Length);
dataStream.Close ();
WebResponse response = request.GetResponse ();
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream ();
StreamReader reader = new StreamReader (dataStream);
string responseFromServer = reader.ReadToEnd ();
Console.WriteLine (responseFromServer);
reader.Close ();
dataStream.Close ();
response.Close();
By default, .NET will tag outgoing POST requests with the header
Expect: 100-Continue. If the server doesn’t support this, it will fail with a 417 error.To get .NET to not do this, execute the following before creating your WebRequest object: