VB.NET怎么把一段JSON数据POST到一个http url上?
vb吧
全部回复
仅看楼主
level 9
YmclVisprect 楼主
VB.NET怎么把一段JSON数据POST到一个http url上?并且获得返回的JSON?
(VB.NET那个帖貌似没人去了,我在那边的帖子都没人回应)
2020年07月03日 04点07分 1
level 8
postdata=你的json
2020年07月03日 05点07分 3
求大佬举个例子
2020年07月03日 05点07分
@YmclVisprect ?!帖子消失了?!
2020年07月03日 05点07分
level 9
YmclVisprect 楼主
【判断结果】
<b>此贴已沉!</b>
2020年07月03日 11点07分 5
我发的看不到吗?改改URL,改改postdata不就行了
2020年07月03日 12点07分
@mijing2000 2楼和4楼都没了
2020年07月03日 12点07分
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分
1