Is it possible to send HTTP POST with some form data with System.Net.WebClient?
If not, is there another library like WebClient that can do HTTP POST? I know I can use System.Net.HttpWebRequest, but I'm looking for something that is not as verbose.
Hopefully it will look like this:
Using client As New TheHTTPLib
client.FormData("parm1") = "somevalue"
result = client.DownloadString(someurl, Method.POST)
End Using
WebClient
doesn't have a direct support for form data, but you can send a HTTP post by using the UploadString method:Based on @carlosfigueira 's answer, I looked further into WebClient's methods and found UploadValues, which is exactly what I want:
The key part is this:
It sends whatever verb I type in, and it also helps me create a properly url encoded form data, I just have to supply the parameters as a namevaluecollection.
As far as the http verb is concerned the
WebRequest
might be easier. You could go for something like:Obviously this lacks exception handling and writing the request body (for which you can use
r.GetRequestStream()
and write it like a regular stream, but I hope it may be of some help.