httpwebrequest for no http headers

W

Will

I have a hardware device that I need to read from. To connect to it
you do a http://<name>/data and it return a few string of raw data(non-
HTML format and no HTTP header). I just need to put that full return
into a string and I would be good to go.

I orginally tried WebClient and had problems so rewrote to
HttpWebRequest for better control. Code will work on properly formed
web pages. Based on recommendations to other error message I have
added the KeepAlive = false and set the useUnsafeHeaderParsing to
true. Doing that remove other problems and now I am stuck with the
WebExeception of

"The underlying connection was closed: The connection was closed
unexpectedly."

That the page returns a few string of non-HTML, and no HTTP header,
the error message is not totally unreasonable.

Are there any methods or properties that will allow me to get the page
in its raw format, or do I have to write my own code to connect to the
port and handle the request?
 
N

Nicholas Paldino [.NET/C# MVP]

Will,

Honestly, for something like this, which doesn't adhere to the HTTP
standard, I wouldn't bother using the HttpWebRequest/HttpWebResponse
classes.

Rather, I would just use the Socket class and connect directly to the
resource. Sending the request is easy enough, and getting the response will
be a matter of just reading off the socket.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top