Blitzkrieg99
04-06-2004, 12:00 AM
Hello everyone.
I tried doing a search and the only results that came out were related to Legacy Visual Basic. Does anyone know how do i go about using the HTTP Post method in .NET? Thanks
excaliber
04-08-2004, 03:57 PM
Dim oWeb As New System.Net.WebClient()
oWeb.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim bytArguments As Byte() = System.Text.Encoding.ASCII.GetBytes("q=InTheory")
Dim bytRetData As Byte() = oWeb.UploadData("http://www.google.com/search", "POST", bytArguments )
debug.Write(System.Text.Encoding.ASCII.GetString(bytRetData))
This declares a new object as a Webclient. We use the Headers.Add method to add in the appropriate headers for form data. Then we create a byte array and set it equal to that search string (q is the query variable for google). We create another byte array that is set to the return value (what the server sends back). It does this by the UploadData method (which accepts the URL, the type of packet, and any arguments).
Then we write it to the debug screen (just for demonstration) by converting back to a string.
Blitzkrieg99
04-11-2004, 08:37 PM
Thanks for that excaliber. Helped a lot. :D