473,614 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3611
System.Net.WebR equest
wr=System.Net.W ebRequest.Creat e("http://www.google.com" );

wr.Timeout=3000 0;

wr.Method="GET" ;

string html="";

try{html=new
System.IO.Strea mReader(wr.GetR esponse().GetRe sponseStream(), System.Text.Enc o
ding.UTF7).Read ToEnd();}

catch(System.Ex ception e)

{

//Timeout and others server errors

}

"C# Learner" <cs****@learner .here> schrieb im Newsbeitrag
news:86******** *************** *********@4ax.c om...
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****@cannabi smail.com> wrote:
System.Net.WebR equest
wr=System.Net.W ebRequest.Creat e("http://www.google.com" );

wr.Timeout=3000 0;

wr.Method="GET" ;

string html="";

try{html=new
System.IO.Strea mReader(wr.GetR esponse().GetRe sponseStream(), System.Text.Enc o
ding.UTF7).Read ToEnd();}

catch(System.Ex ception 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.co m>
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.Strea mReader(wrq.Get Response().GetR esponseStream() ,System.Text.En c
oding.GetEncodi ng(28591)).Read ToEnd();}
"Jon Skeet [C# MVP]" <sk***@pobox.co m> schrieb im Newsbeitrag
news:MP******** *************** *@msnews.micros oft.com...
Zürcher See <aq****@cannabi smail.com> wrote:
System.Net.WebR equest
wr=System.Net.W ebRequest.Creat e("http://www.google.com" );

wr.Timeout=3000 0;

wr.Method="GET" ;

string html="";

try{html=new
System.IO.Strea mReader(wr.GetR esponse().GetRe sponseStream(), System.Text.Enc o ding.UTF7).Read ToEnd();}

catch(System.Ex ception 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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Zürcher See <aq****@cannabi smail.com> wrote:
Sorry it was a copy past of special code, better use:
try{sHtml=new
System.IO.Strea mReader(wrq.Get Response().GetR esponseStream() ,System.Text.En c
oding.GetEncodi ng(28591)).Read ToEnd();}


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

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
"Zürcher See" <aq****@cannabi smail.com> wrote:

<snip>

I guess I'll have to parse the raw packet and add to
WebRequest.Head ers 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
7228
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 and in the debugger I can see the value I want in the property
3
6344
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 to keep those variables, as an alternative, as ViewState variables because I don't want to transfer to many hidden fields. This is the code I use :
8
2393
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 references available but to no avail Also, is it safer (better practise) in an LAN environment to use HTTP requests to access shared files (via ASP.NET) rather than UNC file shares TIA Regards John
12
2855
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 the query string with no url encoding. I must pass the <> characters as they are in the query string. If these characters are url encoded the service rejects the request. This API Url is http://testing.shippingapis.com/ShippingAPITest.dll
0
2210
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 seem to make it work. Please point out the mistakes that I have. Thanks code............. WebRequest = WebRequest.Create(URL) WebRequest.Timeout() = RunInfo.ConnectTimeout WebResponse = WebRequest.GetResponse 'WEBRESPONSE IS A PUBLIC OBJECT...
1
4768
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(); wc.DownloadFile("http://www.microsoft.com/", "MSFT.htm"); .... throws a WebException on the second line. The WebException doesn't specify a problem, but it has an InnerException of type NullReferenceException with the following stack trace:
2
5963
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 application to download images using System.NET classes (webclient, webrequest) asynchronously behind proxy server. The reading method works like this: System.Net.WebClient client=new System.Net.WebClient();
1
8182
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 to SMCHALLANGE=YES to allow me to obtain a session. I then iterate the cookie collection to extract the SMSESSION value. All is good (so far). This is when the sky turns grey and the rain starts to fall. I then use this SMSESSION in a web...
3
9578
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 System.Object, ByVal e As System.EventArgs) Handles OK.Click Dim WebRequest As HttpWebRequest Dim instance As HttpWebRequest =...
3
8167
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 fine, but I need to set and send a cookie with the WebRequest. How do I do that?
0
8179
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8576
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8272
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8427
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6087
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5538
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4119
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1421
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.