470,591 Members | 1,448 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

WebRequest

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
5 3446
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
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
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
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
"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.

Similar topics

17 posts views Thread by James Johnson | last post: by
8 posts views Thread by John K. | last post: by
12 posts views Thread by ThyRock | last post: by
reply views Thread by Gordon | last post: by
2 posts views Thread by kkb | last post: by
3 posts views Thread by eSolTec, Inc. 501(c)(3) | last post: by
3 posts views Thread by Dave | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.