Question Connect to a site via the Post method with httpWebRequest

meher

New member
Joined
Feb 21, 2013
Messages
1
Programming Experience
1-3
Hi friends,

I am trying to develop a function in VB.net that allows me to connect to a website (directory) via the POST method
My objectif is to get a directory the list of companies and their phone number.


var1 var 2 ... are postal code and page number and others variables ....
This is what I found on the net:
Public Sub get_Page()
Dim strNewValue As String
Dim strResponse As String
' Create the request obj
Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://example.com/searchList.do"), HttpWebRequest)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
strNewValue = "var1=1&var2=0&var3=3......"
req.ContentLength = strNewValue.Length
' Write the request
Dim stOut As StreamWriter = New StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)
stOut.Write(strNewValue)
stOut.Close()
' Do the request to get the response
Dim stIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
strResponse = stIn.ReadToEnd()
stIn.Close()
End Sub

The result I got is the source code of the page http://example.com/searchList.do without taking into account the parameters var1, var2 ...
Someone to help me, it's been several days that I'm stuck
thank you
 
Back
Top