You can use the WebClient
class. You need to set the Content-Type
header to application/x-www-form-urlencoded
and then use the UploadData
method. The documentation of that method contains a simple example, which basically boils down to this:
Dim myWebClient As New WebClient()
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim responseArray = myWebClient.UploadData("https://...", "POST", Encoding.ASCII.GetBytes(postData))
Dim response = Encoding.ASCII.GetString(responseArray)
The Wikipedia page of HTTP POST contains information of how the POST data must be encoded:
Each key-value pair is separated by an '&' character, and each key is separated from its value by an '=' character. Keys and values are both escaped by replacing spaces with the '+' character and then using URL encoding on all other characters.
So, your postData
variable can be filled like this (assuming that the fields you want to post are called Username and Password):
Dim postData = String.Format("Username={0}&Password={1}", _
HttpUtility.UrlEncode(username), _
HttpUtility.UrlEncode(password))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…