You can create GET and POST web requests using System.Net.WebRequest class. The procedure is as such:
1. You create a webrequest using
Code:
Dim wrq As System.Net.WebRequest = System.Net.HttpWebRequest.Create("your url here")
2. You specify the method of the request (GET or POST)
Code:
wrq.Method = WebRequestMethods.Http.Post
You don't have to specify the method if you're using GET since it's the default value and you completely skip the steps 3 and 4.
3. Since it's a POST request you should obtain the request stream using
Code:
Dim rqstr As IO.Stream = wrq.GetRequestStream()
4. You write your POST data (setting=value) into the request stream
Code:
Using sw As New IO.StreamWriter(rqstr)
sw.WriteLine("setting=value") ' etc (you should refer to the API docs)
End Using
5. Once you've done you can obtain the server response
Code:
Dim rsp As System.Net.WebResponse
Try
rsp = wrq.GetResponse()
Catch ex As Exception
' Handle errors here
End Try
This is actually the moment the outbound connection is established. Always enclose the call to the GetResponse() method into the Try...Catch block to catch possible exeption
6. Your response object (System.Net.WebResponse) will have the GetResponseStream() method whilch will allow you to get a stream with the data that had been returned from the server.
Code:
Dim htmlsource As String = ""
Using sr As New IO.StreamReader(rsp.GetResponseStream())
htmlsource = sr.ReadToEnd()
End Using
7. Finally, you close the response