Hello Michael,
I think your code logic is absolute right. The error you encounter is
caused by some tiny syntax mistakes. e.g ,
The following statement in your code
Dim response As Net.HttpWebResponse = request.GetResponse()
should be changed to
Dim response As Net.HttpWebResponse = instance.GetResponse()
since you never declared a variable named "request".
Here is a complete code sinppet on using the webrequest to query a remote
http document:
===============================
Protected Sub btnRequest_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnRequest.Click
Dim request As Net.HttpWebRequest
Dim response As Net.HttpWebResponse
Dim url As String = "http://www.microsoft.com"
request = Net.WebRequest.Create(url)
request.Method = "Get"
'optional security setting
request.Credentials = Net.CredentialCache.DefaultCredentials
'optional proxy setting
request.Proxy = New Net.WebProxy("jpnproxy", 80)
response = request.GetResponse()
Dim sr As IO.StreamReader = New
IO.StreamReader(response.GetResponseStream())
Dim responseContent As String = sr.ReadToEnd()
sr.Close()
response.Close()
'content is in responseContent variable
End Sub
===================================
Here are some other web article describing using webrequest component to
access remote http document:
#Downloading Web Pages in VB.NET
http://www.vbdotnetheaven.com/Code/M...esVBNETMCB.asp http://www.vbforums.com/archive/index.php/t-260654.html
Hope this helps some.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.