HttpWebResponse without connecting to Server

  • Thread starter Thread starter Daniel Danilin
  • Start date Start date
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
 
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?
 
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.
 
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();
 
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?
 
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
 
Back
Top