0

I'm having some trouble dealing with the (in)famous exception "The server commited a protocol violation", I'm trying to send a XML string to a given ip address-port and everything seems to be tip-top but this nasty exception is getting on my nerves, I read some fixes like the config file but that did not work, I'm no expert in C# so I guess there is some gruesome error lingering here somewhere, any help would be appreciated!

      string xml = "<Login services=\"NetPage\"/>\n" +
                   "<PageRequest pager=\"2;22\" system_id=\"18\"/>";
       string url = new UriBuilder("http", ipAddress, 3700).ToString();

        using (System.Net.WebClient client = new System.Net.WebClient())
        {
            try
            {
                client.UploadString(url, xml);
            }
            catch(WebException ex)
            {
                throw ex;
            }

        }
stuartd
  • 70,509
  • 14
  • 132
  • 163
  • What does the code look like which handles the request? the error message indicates that the problem is on your server. – Ben Cottrell Mar 13 '17 at 20:35
  • Oh, that will be a hard problem then... it's a proprietary embedded device, I tested the xml command on postui and it worked so I'm trying to code it now in the application – user3533910 Mar 13 '17 at 21:42
  • Several possible solutions here: http://stackoverflow.com/a/2482730/4267590 – khargoosh Mar 14 '17 at 00:44

1 Answers1

0

First thing I'd do is set the HTTP content type correctly before calling upload. Servers often get unhappy when they get unexpected content.

client.Headers.Add("Content-Type","application/xml");
client.UploadString(url, xml);
Ray Fischer
  • 936
  • 7
  • 9