level 9
VB.NET怎么把一段JSON数据POST到一个http url上?并且获得返回的JSON?
(VB.NET那个帖貌似没人去了,我在那边的帖子都没人回应)
2020年07月03日 04点07分
1
level 8
Shared Sub postData()
Dim httpUrl As New System.Uri("你的URL")
Dim req As HttpWebRequest
'req.Timeout = 10000 '设置超时值10秒
req = CType(WebRequest.Create(httpUrl2), HttpWebRequest)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
Dim bytesData() As Byte = System.Text.Encoding.ASCII.GetBytes(你的json")
req.ContentLength = bytesData.Length
Dim postStream As Stream = req.GetRequestStream()
postStream.Write(bytesData, 0, bytesData.Length) '以上向服务器post信息。
Dim res As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse) '以下获取服务器返回信息
Dim reader As StreamReader = _
New StreamReader(res.GetResponseStream, System.Text.Encoding.GetEncoding("GB2312"))'这里编码不一定对,要看你的目标网站
Dim respHTML As String = reader.ReadToEnd()
MsgBox(respHTML) '这就是向网络服务器post后返回的信息
MsgBox(res.StatusCode.ToString) '向网络服务器post后返回的状态码
res.Close() '关闭
End Sub
百度复制的
2020年07月03日 12点07分
6
谢谢大佬;(终于不吞了)
2020年07月03日 16点07分