POST /v1/oauth/accessToken HTTP/1.1
Host:10.1.1.110
Content-Type:application/json
{
"appKey" : "String",
"appSecret" : "String"
}
Sub CallAPI()
Dim url As String
Dim req As Object
Dim jsonStr As String
'定义URL和JSON字符串
url = "http://10.1.1.110/v1/oauth/accessToken"
js"appKey"": ""YourAppKey"", ""appSecret"": ""YourAppSecret""}"
'创建WinHttpRequest对象
Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
'打开连接
req.Open "POST", url, False
'设置请求头
req.SetRequestHeader "Content-Type", "application/json"
'发送POST数据
req.Send (jsonStr)
'获取返回内容
If req.Status = 200 Then
MsgBox req.ResponseText
Else
MsgBox "请求失败:" & req.Status & " " & req.StatusText
End If
'释放对象
Set req = Nothing
End Sub
Dim hc As New HttpClient("http://10.1.1.110/v1/oauth/accessToken")hc.ContentType = "application/json"
Dim jo As New JObject
jo("appKey") = "appKey"
jo("appSecret") = "appSecret"
hc.Content = jo.ToString
Dim ret As String = hc.GetData()
MessageBox.Show(ret)
hc.ContentType = "application/json"提示出错。Unable to cast object of type 'System.String改成hc.Headers.Add("Content-Type", "application/json")
获取不到值。The remote server returned an error: (401) Unauthorized.
有的。如果接口文档不指定在头部添加,建议使用第一种用法
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Foxtable.HttpClient.GetData(Boolean SkipError2)
提示出错,是什么问题
没有权限使用,提交的appKey和appSecret有问题,或者使用的accessToken有问题