By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,449 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,449 IT Pros & Developers. It's quick & easy.

WebRequest

P: n/a
Is it possible to create a WebRequest instance and, instead of giving
it a URI, give it an actual HTTP request?

e.g.:

GET / HTTP/1.1 Host: www.google.com CR LF CR LF

Thanks in advance.
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
System.Net.WebRequest
wr=System.Net.WebRequest.Create("http://www.google.com");

wr.Timeout=30000;

wr.Method="GET";

string html="";

try{html=new
System.IO.StreamReader(wr.GetResponse().GetRespons eStream(),System.Text.Enco
ding.UTF7).ReadToEnd();}

catch(System.Exception e)

{

//Timeout and others server errors

}

"C# Learner" <cs****@learner.here> schrieb im Newsbeitrag
news:86********************************@4ax.com...
Is it possible to create a WebRequest instance and, instead of giving
it a URI, give it an actual HTTP request?

e.g.:

GET / HTTP/1.1 Host: www.google.com CR LF CR LF

Thanks in advance.

Nov 15 '05 #2

P: n/a
Zürcher See <aq****@cannabismail.com> wrote:
System.Net.WebRequest
wr=System.Net.WebRequest.Create("http://www.google.com");

wr.Timeout=30000;

wr.Method="GET";

string html="";

try{html=new
System.IO.StreamReader(wr.GetResponse().GetRespons eStream(),System.Text.Enco
ding.UTF7).ReadToEnd();}

catch(System.Exception e)

{

//Timeout and others server errors

}


Why are you specifying UTF7 there? That's *very* rarely used, IME. Far
more likely is UTF8.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

P: n/a
Sorry it was a copy past of special code, better use:
try{sHtml=new
System.IO.StreamReader(wrq.GetResponse().GetRespon seStream(),System.Text.Enc
oding.GetEncoding(28591)).ReadToEnd();}
"Jon Skeet [C# MVP]" <sk***@pobox.com> schrieb im Newsbeitrag
news:MP************************@msnews.microsoft.c om...
Zürcher See <aq****@cannabismail.com> wrote:
System.Net.WebRequest
wr=System.Net.WebRequest.Create("http://www.google.com");

wr.Timeout=30000;

wr.Method="GET";

string html="";

try{html=new
System.IO.StreamReader(wr.GetResponse().GetRespons eStream(),System.Text.Enco ding.UTF7).ReadToEnd();}

catch(System.Exception e)

{

//Timeout and others server errors

}


Why are you specifying UTF7 there? That's *very* rarely used, IME. Far
more likely is UTF8.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

P: n/a
Zürcher See <aq****@cannabismail.com> wrote:
Sorry it was a copy past of special code, better use:
try{sHtml=new
System.IO.StreamReader(wrq.GetResponse().GetRespon seStream(),System.Text.Enc
oding.GetEncoding(28591)).ReadToEnd();}


Well, better actually is to use whatever content encoding the server
returns. That's what HttpWebResponse.ContentEncoding is for, IMO.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5

P: n/a
"Zürcher See" <aq****@cannabismail.com> wrote:

<snip>

I guess I'll have to parse the raw packet and add to
WebRequest.Headers manually then.

Hmm... I wonder why they didn't include functionality for this, since
the headers are going to have to be translated into a raw packet
anyway, before the actual request is sent.

Nothing's perfect, I s'pose.

Thanks for the response.
Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.