vbnet HTTP Request and Response

Dim uri As New Uri("http://example.com/")
Dim request As HttpWebRequest
Dim response As HttpWebResponse
Dim ResponseData As String = "" 'returned response

If (uri.Scheme = uri.UriSchemeHttp) Then
	'build up the request
	request = HttpWebRequest.Create(uri)
	request.Method = WebRequestMethods.Http.Post
	request.Timeout = 60000 '1000ms = 1 second
	request.UserAgent = "Googlebot"

	'get the data to post
	Dim DataString As String = File.ReadAllText("C:\websites\Upload.txt")
	Dim PostData() As Byte = System.Text.Encoding.Default.GetBytes(DataString.ToString())
	request.ContentLength = PostData.Length

	'write the data to the request stream
	Dim TempStream As Stream = request.GetRequestStream()
	TempStream.Write(PostData, 0, PostData.Length)

	'get the response of the request
	response = request.GetResponse
	Dim reader As New StreamReader(response.GetResponseStream())
	ResponseData = reader.ReadToEnd
	ResponseData = "URL is invalid or not HTTP"
End If

'display/log the Response for debugging
Posts a request to a web page and retrieves the response.

Updated: Saturday 9th October 2010, 23:21pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.