Foxtable(狐表)用户栏目专家坐堂 → postman提交没问题,HttpClient提交有问题


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

主题:postman提交没问题,HttpClient提交有问题

帅哥,在线噢!
aidimeng
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:794 积分:7652 威望:0 精华:0 注册:2015/9/14 14:26:00
postman提交没问题,HttpClient提交有问题  发帖心情 Post By:2024/1/15 12:15:00 [只看该作者]

在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编辑过]

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110334 积分:561518 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:794 积分:7652 威望:0 精华:0 注册:2015/9/14 14:26:00
  发帖心情 Post By:2024/1/15 15:34:00 [只看该作者]

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:111.txt

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

 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110334 积分:561518 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:794 积分:7652 威望:0 精华:0 注册:2015/9/14 14:26:00
  发帖心情 Post By: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编辑过]

 回到顶部
帅哥,在线噢!
有点蓝
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110334 积分:561518 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2024/1/15 16:39:00 [只看该作者]

Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.tls12

 回到顶部
帅哥,在线噢!
aidimeng
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:794 积分:7652 威望:0 精华:0 注册:2015/9/14 14:26:00
  发帖心情 Post By:2024/1/15 16:41:00 [只看该作者]

感谢感谢,终于可以了,辛苦了

 回到顶部