HttpWebRequest
HttpWebRequest
HttpWebRequest
HttpWebRequest
HttpWebRequest
HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest
HttpWebRequest HttpWebRequest
HttpWebRequest
Go Back  Xtreme Visual Basic Talk > > > HttpWebRequest


Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2004, 06:44 PM
wowzers wowzers is offline
Newcomer
 
Join Date: Oct 2004
Location: Hobart
Posts: 11
Default HttpWebRequest


Hello,

I have migrated an application I developed in Visual Basic 6 to Visual Basic.NET and have been researching how I should go about converting the functions I use. I have been using the Internet Control (Inet) to connect to web pages and download their source code, i.e. Inet.OpenURL("www.google.com/").

Now that I am in .NET I won't be using this control because it is not supported (well as I've found it is but I shouldn't use it anyway!). I have been led to believe I should be using the System.Net list of classes to complete the same task I have in Visual Basic 6. I'm narrowed it down (well I think anyway) to the System.Net.HttpWebRequest class. However I'm finding it very diffucult figuring out how to use its functions

Does anyone know how to use this like the old Inet.OpenURL function? I just want to download a pages source and store it in a variable/text box/text file, or the like. MSDN explains all the functions and this is where I have found my information so far, I just can't figure out from there how to use it lol. If anyone knows how to use this or knows of a better way to complete this Inet.OpenURL type function in .NET I'ld really appreciate if you help me out. Thank you.

Regards.
Reply With Quote
  #2  
Old 10-11-2004, 11:03 PM
PlenoJure's Avatar
PlenoJureHttpWebRequest PlenoJure is offline
'With Full Right'

Retired Moderator
* Guru *
 
Join Date: Jun 2003
Posts: 1,880
Default

Here's an example based on the System.Net.WebClient class example code:
Code:
Public Function OpenURL(ByVal strURL As String) As String Dim client As New System.Net.WebClient Dim data As System.IO.Stream = client.OpenRead(strURL) Dim reader As New System.IO.StreamReader(data) Dim s As String = reader.ReadToEnd() data.Close() reader.Close() Return s End Function
And here is one based on the System.Net.HttpWebRequest.GetResponse Method example code:
Code:
Public Function OpenURL(ByVal strURL As String) As String Dim request As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(strURL), System.Net.HttpWebRequest) Dim response As System.Net.HttpWebResponse = CType(request.GetResponse(), System.Net.HttpWebResponse) Dim receiveStream As System.IO.Stream = response.GetResponseStream() Dim readStream As New System.IO.StreamReader(receiveStream, System.Text.Encoding.UTF8) Dim s As String = readStream.ReadToEnd() response.Close() readStream.Close() Return s End Function

Usage:
Code:
MessageBox.Show(OpenURL("http://www.google.com"))

I think thats what you are after..
__________________
Adam
-- Please use [vb][/vb] tags for code | Posting Guidelines | Please check the MSDN and Search before posting
-- Other Sites: Did you search Google first? | My Blog
Reply With Quote
  #3  
Old 10-12-2004, 05:17 PM
wowzers wowzers is offline
Newcomer
 
Join Date: Oct 2004
Location: Hobart
Posts: 11
Default

Thank you so much PlenoJure. I couldn't continue my application without this code, very much appreciated.

Regards.
Reply With Quote
  #4  
Old 11-03-2004, 01:41 AM
newignasius newignasius is offline
Newcomer
 
Join Date: Nov 2004
Posts: 1
Default Help me, please!!!

PlenoJure, I used your code in pocket pc 2002 (.net compact framework), but it didn't work. I am new in pocket pc developer. Can you help me to correct your code, so it will work in pocket pc? Thanks for your help.
Reply With Quote
  #5  
Old 11-07-2004, 10:53 PM
netsurfer013 netsurfer013 is offline
Newcomer
 
Join Date: May 2004
Posts: 7
Default Downloading web pages

Is it possible to save complete web pages to the hard disk using those classes, like when you go File|Save As... on Internet Explorer?
Reply With Quote
  #6  
Old 11-08-2004, 07:55 AM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

Quote:
Originally Posted by netsurfer013
Is it possible to save complete web pages to the hard disk using those classes, like when you go File|Save As... on Internet Explorer?
You could download all the bytes to a byte array, convert them to a string and save it with a filestream and stream writer.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
HttpWebRequest
HttpWebRequest
HttpWebRequest HttpWebRequest
HttpWebRequest
HttpWebRequest
HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest HttpWebRequest
HttpWebRequest
HttpWebRequest
 
HttpWebRequest
HttpWebRequest
 
-->