1

I am trying to receive HTTP content from a small embedded Chinese device. The device's inbuilt web server accepts headers but does not return any on the response.

ie

Raw Response: (2 lines, 1 is the XML the second is blank \n)

<?xml version="1.0" encoding="utf-8"?><document><userkey>key</userkey> <machinemode>1</machinemode><serial>0000</serial><unitname>Device</unitname><version>1</version></document>\n

Fiddler will not show the response at all. Using HttpWebRequest and WebClient yields no results as there are no headers in the response and this results in an exception. Some of the research I have done points to adding the useUnsafeHeaderParsing into the application config (and/or setting it programmatically). This does not work at all. I still receive

System.Net.WebException was unhandled Message=The server committed a protocol violation. Section=ResponseStatusLine Source=System StackTrace: at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)

Is there a work around for this? Without using Sockets/TCPClient is there an alternative way of receiving data from a server that provides no headers?

Jeremy
  • 3,880
  • 3
  • 35
  • 42

1 Answers1

1

I couldn't figure out how to get WebClient nor HttpWebRequest to work for accessing the response in such a scenario, so unfortunately i think you're left with TcpClient :(

James Manning
  • 13,429
  • 2
  • 40
  • 64
  • The response property of the `WebException` is null and the status is `ServerProtocolViolation`. You had my hopes up for a second though. – Jeremy May 06 '12 at 06:39
  • 1
    Sorry - I tried a few things with WebClient, WebRequest, and HttpWebRequest, but couldn't get anything to work. In case it helps, I put up a quick sample using TcpClient and TcpListener. :) https://gist.github.com/2622054 – James Manning May 06 '12 at 13:17
  • Thank you very much for your code sample. I had also tinkered with TcpClient as well and was preferring not to take that path, but looks to be the only option. My code didn't use `await` and was not able to read the entire stream if the response was over the buffer. Please edit the question to suggest the use of `TcpClient` and I shall mark it as answered. Thank you once again for your time :) – Jeremy May 06 '12 at 23:48
  • 1
    Combining `TcpClient` `NetworkStream` and this http://www.yoda.arachsys.com/csharp/readbinary.html to result in a blocking reader - which is the requirement. – Jeremy May 07 '12 at 01:00