Click here to Skip to main content
12,762,098 members (35,411 online)
Click here to Skip to main content
Articles » Languages » VB.NET » General » Downloads


24 bookmarked
Posted 10 Jun 2002

WebResourceProvider VB.NET style

, 30 Aug 2002
Ravi Bhavnani's WebResourceProvider ported to the .NET Framework
I just strugged with this recently as well. If you are not sending
parameters, then you set the ContentLength to 0. In that case, using
WebClient is easier. With parameters, I've found the UploadParameters method
of WebClient to be the simplest. Here's some sample code. The first two are
different implementions for a POST with no parameters. The third sets

Imports System.Net
Imports System.IO

Private Sub submitPost_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles submitPost.Click
If httpPostAddress.Text <> "" Then
Dim postRequest As WebRequest
Dim postResponse As WebResponse
Dim responseStream As Stream
Dim responseReader As StreamReader
Dim responseText As String

postRequest = WebRequest.Create(httpPostAddress.Text)
With postRequest
.ContentLength = 0
.Method = "POST"
.ContentType = "application/x-www-form-urlencoded"
End With
postResponse = postRequest.GetResponse()
responseStream = postResponse.GetResponseStream()
responseReader = New StreamReader(responseStream)
responseText = responseReader.ReadToEnd
postReturnValue.Text = responseText
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, _
End Try
End If
End Sub

Private Sub submitPostWebClient_Click(ByVal sender As System.Object, ByVal
e As _
System.EventArgs) Handles submitPostWebClient.Click

If httpPostAddress.Text <> "" Then
Dim webClientID As WebClient = New WebClient()
Dim responseStream As Stream = webClientID.OpenRead(httpPostAddress.Text)
Dim responseReader As New StreamReader(responseStream)
Dim responseText As String = responseReader.ReadToEnd

postReturnValue.Text = responseText
End If
End Sub

Private Sub submitPostParameters_Click(ByVal sender As System.Object, ByVal
e As _
System.EventArgs) Handles submitPostParameters.Click

If emailAddress.Text <> "" Then
Dim webAddress As String = urlWithParameters.Text
Dim webClientID As WebClient = New WebClient()
Dim parameterTable As New

With parameterTable
.Add("email", emailAddress.Text)
.Add("name", nameBox.Text)
.Add("location", locationBox.Text)
End With

Dim responseArray As Byte() = webClientID.UploadValues(webAddress,
"POST", _
postReturnValue.Text =
End If
End Sub

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Switzerland Switzerland
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 31 Aug 2002
Article Copyright 2002 by Cello
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid