Rss & SiteMap

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

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

标题:foxtable调用这个接口代码需要怎么写

1楼
yuweijie 发表于:2024/3/28 12:42:00
POST /v1/oauth/accessToken HTTP/1.1
Host:10.1.1.110
Content-Type:application/json

{
	"appKey" : "String",
	"appSecret" : "String"
}
2楼
myjht 发表于:2024/3/28 13:34:00
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
3楼
有点蓝 发表于:2024/3/28 13:50:00
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)
4楼
yuweijie 发表于:2024/3/28 17:10:00
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.
5楼
有点蓝 发表于:2024/3/28 17:30:00
这句代码没有问题,应该是给json对象赋值出错了
6楼
yuweijie 发表于:2024/3/28 18:11:00
hc.ContentType = "application/json"

hc.Headers.Add("Content-Type", "application/json")
两句有区别吗?

7楼
有点蓝 发表于:2024/3/28 20:14:00
有的。如果接口文档不指定在头部添加,建议使用第一种用法
8楼
yuweijie 发表于:2024/3/29 17:20:00
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()
   at Foxtable.HttpClient.GetData(Boolean SkipError2)


提示出错,是什么问题
9楼
有点蓝 发表于:2024/3/29 17:35:00
没有权限使用,提交的appKey和appSecret有问题,或者使用的accessToken有问题
10楼
yuweijie 发表于:2024/3/29 20:31:00
你这个要import啥吧
共17 条记录, 每页显示 10 条, 页签: [1] [2]

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

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