0

I am trying to send XML generated to an URL, I keep getting error with HttpWebResponse:

The remote server returned an error:(417) Expectation failed

This is my code.

 //POST to URL 

            var httpRequest = (HttpWebRequest)WebRequest.Create("http://xxx.xxx.xxx.xxx:8000");
            httpRequest.Method = "POST";
            httpRequest.ContentType = "text/xml; charset=utf-8";
            httpRequest.ProtocolVersion = HttpVersion.Version11;


            //Set appropriate headers 

            var xmlWriterSettings = new XmlWriterSettings
            {
                NewLineHandling = NewLineHandling.None,
                Encoding = Encoding.ASCII
            };

            using (var requestStream = httpRequest.GetRequestStream())
            {
                xmlDoc.Save(requestStream);

            }

            using (var response = (HttpWebResponse)httpRequest.GetResponse())
            using (var responseStream = response.GetResponseStream())
            {
                // Response Code to see if the request was successful
                var responseXml = new XmlDocument();
                responseXml.Load(responseStream);
                using (var repp = XmlWriter.Create("response.xml"))
                {
                    responseXml.Save(repp);
                }
            }
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • The remote server returned an error:(417) Expectation failed – user2922687 Oct 27 '13 at 15:47
  • 417 means that the server could not fulfill the requirements indicated by the client via `Expect` HTTP headers. I am not familiar with `HttpWebRequest` and its default headers but could you inspect the actual HTTP headers being sent, in particular any Expect headers? – JayK Oct 27 '13 at 18:42
  • 1
    Looks like this? - http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c – Snixtor Oct 27 '13 at 20:55
  • While this has nothing to do with your actual question, I'd like to point out the inconsistency between stating that the content type is `"text/xml; charset=utf-8"`, and then using `Encoding.ASCII`. – Kris Vandermotten Oct 28 '13 at 13:20
  • Thanks guys managed to fix it, just had to change the `HttpWebRequest.ProtocolVersion` to `HttpVersion.Version10` – user2922687 Oct 29 '13 at 09:39

0 Answers0