HttpWebResponse without connecting to Server

D

Daniel Danilin

How can I use HttpWebResponse without realy connecting to a WebServer, and
only use it, for example, to parse HTTP Response from a file or byte array,
or a stream? Or is there other way without to self implement HTTP Protocol?

Thanks
Daniel
 
J

John Saunders

Daniel Danilin said:
How can I use HttpWebResponse without realy connecting to a WebServer, and
only use it, for example, to parse HTTP Response from a file or byte array,
or a stream? Or is there other way without to self implement HTTP
Protocol?

HttpWebResponse does not parse HTML.

What are you trying to accomplish?
 
J

John Saunders

Daniel Danilin said:
I don't want to parse HTML. I need to parse HTTP and get Data from it.

The term "parse HTTP" doesn't really make sense, as HTTP is a network
protocol. Perhaps what you mean is that you want to parse the string
resulting from a complete HTTP response? If so, you should realize that the
format is pretty easy: skip past the headers, and there's your data. The
headers are separated from the data by a single blank line.

Note that this only makes sense if the response came in a single message. If
the response was chunked, for instance, then you've got some thinking to do
about what "parse HTTP" means.
 
D

Daniel Danilin

I want something like this:

byte[] payload = tcpPacket.Data;
HttpWebResponse response = new HttpWebResponse(payload);
int length = response.ContentLength;
string type = response.ContentType;
CookieCollection cookies = response.Cookies;
Stream s = response.GetResponseStream();
 
J

John Saunders

Daniel Danilin said:
I want something like this:

byte[] payload = tcpPacket.Data;
HttpWebResponse response = new HttpWebResponse(payload);
int length = response.ContentLength;
string type = response.ContentType;
CookieCollection cookies = response.Cookies;
Stream s = response.GetResponseStream();

Sorry, no such thing.

Are you expecting the entire response to be in tcpPacket.Data? What if the
response arrived in several packets?
 
D

Daniel Danilin

Well, then it could be possible to do this:

HttpParser parser = new HttpParser();
parser.PacketArrived += PacketEventHandler(parser_PacketArrived);

parser.AddPacket(payload);

and when all packets in parser, we get event PacketArrived


John Saunders said:
Daniel Danilin said:
I want something like this:

byte[] payload = tcpPacket.Data;
HttpWebResponse response = new HttpWebResponse(payload);
int length = response.ContentLength;
string type = response.ContentType;
CookieCollection cookies = response.Cookies;
Stream s = response.GetResponseStream();

Sorry, no such thing.

Are you expecting the entire response to be in tcpPacket.Data? What if the
response arrived in several packets?
--
John Saunders
johnwsaundersiii at hotmail

that
the message. to
do
 

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