472,785 Members | 1,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,785 software developers and data experts.

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 3557
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: James Johnson | last post by:
Dear C#dex, I define a variable: HttpWebRequest webRequest and run the following request webRequest = WebRequest.Create(TARGET_URL) as HttpWebRequest; The webRequest object returns values...
3
by: Paul | last post by:
Hello, First I want to refer to the problem "WebRequest : execute a button" of a few days ago. The way I solved it, I loose my session, and as a consequence my session variables. I don't want...
8
by: John K. | last post by:
Hi I was wondering if it's possible to use the WebRequest class to access a file on windows shared folder with authentication? If yes, what would the syntax be? I've tried to look this up in the...
12
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts...
0
by: Gordon | last post by:
I use the following code to get source HTML. The second line seems to work when I get no response from a site. However, I want to stop the request if it's taking more than 20 - 30 seconds. I can't...
1
by: David Satz | last post by:
Hello--I just upgraded to Visual Studio .NET 2005 and suddenly, all my .NET 1.1 applications that accessed Web sites have broken. For example, this code: WebClient wc = new WebClient();...
2
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an...
1
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
3
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to create a call to a web page to validate and register software. The code I'm using is: Private Sub OK_Click(ByVal sender As...
3
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.