Foxtable(狐表)用户栏目专家坐堂 → HttpClient的post请求问题


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

主题:HttpClient的post请求问题

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


加好友 发短信
等级:三尾狐 帖子:760 积分:5430 威望:0 精华:0 注册:2012/10/5 21:53:00
HttpClient的post请求问题  发帖心情 Post By:2021/12/13 16:20:00 [只看该作者]

在对方的网页API测试环境中post请求参数:
curl 
 -X POST "http://192.168.3.10:8088/api/services/Org/UserLogin" -H "accept: application/json" -H "Content-Type: text/json" -d "{ \"UserName\": \"000001\", \"Password\": \"12345\", \"DomainIp\": \"\", \"DeviceId\": \"\", \"WeChatName\": \"\", \"IsWechatType\": \"\", \"ClientType\": \"\", \"UserHostAddress\": \"\", \"ValidateCodeSms\": \"\"}"

测试请求的参数是这样的
{
  "UserName": "000001",
  "Password": "12345",
  "DomainIp": "",
  "DeviceId": "",
  "WeChatName": "",
  "IsWechatType": "",
  "ClientType": "",
  "UserHostAddress": "",
  "ValidateCodeSms": ""
}

返回结构
{
  "data": "0064a97bae66bf3647f29aad065d67975a38",
  "dataDescription": "",
  "result": 0,
  "message": ""
}

但是我用HttpClient请求结果没有返回任何结果
Dim url As String = "http://192.168.3.10:8088/api/services/Org/UserLogin"
Dim hc As New HttpClient(url)
Dim jo As New JObject
jo("UserName") = "000001"
jo("Password") = "12345"
jo("DomainIp") = ""
jo("DeviceId") = ""
jo("WeChatName") = ""
jo("IsWechatType") = ""
jo("ClientType") = ""
jo("UserHostAddress") = ""
jo("ValidateCodeSms") = ""
Output.Show(jo.tostring)
hc.FormData.Add("userDto",jo.tostring)
Dim ret  As String = hc.GetData
Output.Show(ret)

返回结果是一个空,这个是哪的问题?

[此贴子已经被作者于2021/12/13 16:20:18编辑过]

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


加好友 发短信
等级:超级版主 帖子:110758 积分:563716 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/12/13 16:23:00 [只看该作者]

Dim url As String = "http://192.168.3.10:8088/api/services/Org/UserLogin"
Dim hc As New HttpClient(url)
hc.ContentType = "application/json"
Dim jo As New JObject
jo("UserName") = "000001"
jo("Password") = "12345"
jo("DomainIp") = ""
jo("DeviceId") = ""
jo("WeChatName") = ""
jo("IsWechatType") = ""
jo("ClientType") = ""
jo("UserHostAddress") = ""
jo("ValidateCodeSms") = ""
Output.Show(jo.tostring)
hc.Content = jo.tostring
Dim ret  As String = hc.GetData
Output.Show(ret)
[此贴子已经被作者于2021/12/13 16:23:52编辑过]

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


加好友 发短信
等级:三尾狐 帖子:760 积分:5430 威望:0 精华:0 注册:2012/10/5 21:53:00
  发帖心情 Post By:2021/12/13 16:42:00 [只看该作者]

非常感谢,可以了,被对方的API文档误导了,对方写了POST请求,并写了传入字段userDto

 回到顶部