Foxtable(狐表)用户栏目专家坐堂 → 调用接口,post形式


  共有1350人关注过本帖树形打印复制链接

主题:调用接口,post形式

帅哥哟,离线,有人找我吗?
bzqlyj
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:271 积分:2240 威望:0 精华:0 注册:2020/9/28 14:53:00
调用接口,post形式  发帖心情 Post By:2024/5/10 10:49:00 [显示全部帖子]

使用以下代码,运行错误,未能创建 SSL/TLS 安全通道。如何处理


Dim name As String="张三"
Dim id As String="abc"
Dim msg As String = "username=" & name &"&idcard=" & id 
msgbox(msg)
Dim req = System.Net.WebRequest.Create("https://certificate/query_json.xhtml")
req.Method = "POST"
req.Timeout = 5000
req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:66.0) Gecko/20100101 Firefox/66.0"
Dim aryBuf As Byte() = Encoding.GetEncoding("utf-8").GetBytes(msg)
req.ContentLength = aryBuf.Length
Dim writer = req.GetRequestStream()
writer.Write(aryBuf, 0, aryBuf.Length)
writer.Close()
writer.Dispose()
Dim pos = req.GetResponse
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim str As String = reader.ReadToEnd
pos.Close
stm.Close
reader.close

msgbox(str)


 回到顶部
帅哥哟,离线,有人找我吗?
bzqlyj
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:271 积分:2240 威望:0 精华:0 注册:2020/9/28 14:53:00
回复:(有点蓝)Net.ServicePointManager.SecurityPr...  发帖心情 Post By:2024/5/10 11:11:00 [显示全部帖子]

用以上Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls1 
运行错误,必须先将 ContentLength 字节写入请求流,然后再调用 [Begin]GetResponse。
Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls13  此处修改为Tls12、Tls13,远程服务器返回错误: (415) Unsupported Media Type。

 回到顶部