I've got a small sockets application where I communicate with a web server
via async sockets method.
Using the ASCIIEncoding Class, I convert strings to byte arrays (and vice
versa) in conjunction with beginSend and beginReceive (and their
corresponding callbacks). So long as the web server and I just deal in
text, life is easy.
Now there's an image I want to request and then display in my app, it's a
dynamic PNG image that's generated by some .aspx page on the web server. So
my GET, to request this image, looks like this:
GET /MakeThePNG.aspx HTTP/1.1
Host: www.url.com
And here's the website's response:
HTTP/1.1 200 OK
Date: Thu, 01 Dec 2005 20:28:01 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Transfer-Encoding: chunked
Cache-Control: private, max-age=1800
Content-Type: image/png
39c9
?PNG
<a bunch of data>
0
I need to turn this response (sans the header, I'm assuming, but I'm unsure
which portions of the body) into an image object that I can display in a
picture box & save to disk. I've tried messing around with a Memory Stream,
and with that, tried including the whole body portion, just the <a bunch of
data> portion, but my attempts thus far are ultimately met with an Invalid
Argument exception when I try to make a new Image.FromStream with my Memory
Stream. I've tried to save said portions of the buffer to disk, but it does
not make a valid png file. So I'm not carving the data out of the body
correctly, or, it's not encoded correctly, or... ? I'm stumped.