以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  postman提交没问题,HttpClient提交有问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=190079)

--  作者:aidimeng
--  发布时间:2024/1/15 12:15:00
--  postman提交没问题,HttpClient提交有问题
在postman上提交报文没问题,通过HttpClient 提交提示 远程服务器返回错误: (405) 不允许的方法
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:水表接入规范v20231219.zip



图片点击可在新窗口打开查看此主题相关图片如下:微信图片_20240115121421.png
图片点击可在新窗口打开查看

 Dim version As String = "1.0"
\'   Dim encoding As String = "utf8"
 Dim BasicTime As New Date(1970, 1, 1, 8, 0, 0)
Dim NowTime As Date = Date.Now \'当前时间
Dim TimeStamp As Long = CLng((NowTime - BasicTime).TotalSeconds())
Dim imei_no As String = "65270065264270"
Dim meter_no As String = "53188028"
Dim jo1 As New JObject
jo1("imei_no") = imei_no 
jo1("meter_no") = meter_no 
Dim s As String = CompressJson(jo1)
 Dim content As String = Convert.ToBase64String(Encoding.UTF8.GetBytes(s))
Output.Show("content:" & content)
 Dim signature As String = content & version & "utf8" & TimeStamp & "10" & version & "123456"
 signature = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(signature, "MD5").Tolower
Output.Show("signature:" & signature)
Dim url As String = "https://www.iotmeter.top:91/api/meterOperate"
Dim jo As New JObject
jo("version") = version
jo("encoding") = "utf8"
jo("timestamp") = timestamp
jo("signature") = signature
jo("signmethod") = "01"
jo("transtype") = "10"
jo("content") = content
Dim hc As New HttpClient(url)
hc.C
 Dim s1 As String = CompressJson(jo)
 Output.Show(s1)
Dim ret As String = hc.GetData()
Output.Show(ret)
 远程服务器返回错误: (405) 不允许的方法
[此贴子已经被作者于2024/1/15 12:27:27编辑过]

--  作者:有点蓝
--  发布时间:2024/1/15 14:24:00
--  
……
Dim hc As New HttpClient(url)
hc.ContentType = "application/json"
 Dim s1 As String = CompressJson(jo)
 Output.Show(s1)
 hc.Content = s1
Dim ret As String = hc.GetData()
Output.Show(ret)

--  作者:aidimeng
--  发布时间:2024/1/15 15:34:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:111.txt

必须先将 ContentLength 字节写入请求流,然后再调用 [Begin]GetResponse。

--  作者:有点蓝
--  发布时间:2024/1/15 16:16:00
--  
 Dim signature As String = cexp("content={0}&encoding=utf8&signmethod=01&timestamp={1}&transtype=10&version=1.0&key=123456",content ,TimeStamp )
signature = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(signature, "MD5").Toupper

--  作者:aidimeng
--  发布时间:2024/1/15 16:24:00
--  
还是一样的提示
 Dim signature As String = cexp("content={0}&encoding=utf8&signmethod=01&timestamp={1}&transtype=10&version=1.0&key=123456", content , TimeStamp)
signature = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(signature, "MD5").Toupper
Dim url As String = "https://www.iotmeter.top:91/api/meterOperate/"
Dim jo As New JObject
jo("version") = version
jo("encoding") = "utf8"
jo("timestamp") = timestamp
jo("signature") = signature
jo("signmethod") = "01"
jo("transtype") = "10"
jo("content") = content
Dim hc As New HttpClient(url)
hc.C
 Dim s1 As String = CompressJson(jo)
  Output.Show(s1) ‘显示;{"version":"1.0","encoding":"utf8","timestamp":1705306964,"signature":"153689B8AB7E968CE0718F2A2D6191D7","signmethod":"01","transtype":"10","content":"eyJpbWVpX25vIjoiNjUyNzAwNjUyNjQyNzAiLCJtZXRlcl9ubyI6IjUzMTg4MDI4In0="}
 hc.Content = s1
Dim ret As String = hc.GetData()
Output.Show(ret)
[此贴子已经被作者于2024/1/15 16:25:35编辑过]

--  作者:有点蓝
--  发布时间:2024/1/15 16:39:00
--  
Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.tls12
--  作者:aidimeng
--  发布时间:2024/1/15 16:41:00
--  
感谢感谢,终于可以了,辛苦了