vb.net - VB.net HTTP POST 请求
问题描述
我意识到关于这个主题有几个类似的帖子,但我还没有找到解决方案。我想通过 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
解决方案
对于那些对结果感兴趣的人。这是解决方案的主题。
推荐阅读
- flowtype - 重用流型类声明
- postgresql - PostgresSQL:更新表B中的某些列后更新表B中的某些列
- python - 单击按钮时打开一个新窗口|| PyQt5
- ios - 如何使用 MDCAlertController Material Design 禁用触摸屏外关闭视图 - swift
- javascript - Chrome 扩展,在执行脚本之前更改变量的值
- swift - 应用程序在后台后未调用 URLSessionDownloadDelegate 方法 didWriteData
- servicestack - 使用 ServiceStack Ormlite 的元组中的枚举值引发空引用异常
- java - Java - 在没有 POJO 的情况下递归地从 JSON 字符串中删除字段
- php - 从服务器中删除不同文件夹但名称相同的两个文件 PHP
- angular6 - 角度6:星云主题,改变布局和网址