Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共4 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:调用接口,post形式

1楼
bzqlyj 发表于: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)

2楼
有点蓝 发表于:2024/5/10 11:00:00
Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls11 '不行就Tls12、Tls13都试一遍
Dim hc As New HttpClient("https://certificate/query_json.xhtml")
hc.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:66.0) Gecko/20100101 Firefox/66.0"
hc.ContentType = "application/x-www-form-urlencoded"
hc
.Timeout = 5 '设置超时为5秒
hc.FormData.Add("username",name )
hc.FormData.Add("idcard",id)
Dim ret As String = hc.GetData()
MessageBox
.Show(ret)
3楼
bzqlyj 发表于: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。
4楼
有点蓝 发表于:2024/5/10 11:17:00
https://www.baidu.com/s?wd=System.Net.WebRequest%20ssl
共4 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02344 s, 2 queries.