Programmatically posting form data to a web page and getting result in .net

G

Ghafran Abbas

To programmatically post form data to a web page and get the result in
..net, use the following code.

===========Begin Code================

Imports System.Net

Public Sub PostDataToForm()

'URL to post the data to
Dim strPostText As String = "http://www.google.com"

Dim myWebClient As New WebClient
Dim mypostvalues As New NameValueCollection

'Add Post Fields Here
'The first parameter is the name of the field, the second is the
value
mypostvalues.Add("hl", "en")
mypostvalues.Add("q", "test search")

Try
Dim responseData As Byte() = myWebClient.UploadValues(strPostText,
mypostvalues)
sResponse = Encoding.ASCII.GetString(responseData)
Catch
'Handle Error Here
Finally
myWebClient.Dispose()
End Try

End Function

===========End Code================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top