[英]VB.net HTTP POST request
我意識到關於這個主題有幾個類似的帖子,但我還沒有找到解決方案。 我想通過 POST 請求發送下面字段中的數據。
這是我到目前為止所做的代碼。
Dim result = ""
Dim URL = "http://derogations/index.php"
'Create a New WebClient instance.
Dim myWebClient = New WebClient()
Dim LeMessage As String
LeMessage = "filtre_statut=*"
LeMessage &= "&filtre_client=*"
LeMessage &= "&filtre_type=*"
LeMessage &= "&filtre_demandeur=*"
LeMessage &= "&filtre_validateur=*"
LeMessage &= "&filtre_recherche=RATNOV0025AB"
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
'Display the headers in the request
MsgBox(myWebClient.Headers.ToString())
'Apply ASCII Encoding to obtain the string as a byte array.
Dim byteArray() As Byte = Encoding.ASCII.GetBytes(LeMessage)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
ServicePointManager.ServerCertificateValidationCallback += New System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate)
Dim req = CType(WebRequest.Create(URL), HttpWebRequest)
req.AllowWriteStreamBuffering = True
req.ContentType = "application/x-www-form-urlencoded"
req.Method = "POST"
'req.ContentLength = bytes.Length;
req.KeepAlive = False
req.ProtocolVersion = HttpVersion.Version10
'req.Timeout = -1;
Try
Using writer As New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
writer.WriteLine(byteArray)
End Using
Using resp As WebResponse = req.GetResponse()
Using sr As StreamReader = New StreamReader(resp.GetResponseStream())
result = sr.ReadToEnd()
End Using
End Using
Catch ex As Exception
result = MsgBox(ex.ToString)
End Try
對於那些對結果感興趣的人。 這是解決方案的主題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.