使用VBA连接到API
我需要帮助才能获得授权才能连接到API。给定的命令行
curl -X GET "https://app.mysite.fr/api/v1/societe/11111111" -H "Authorization: Bearer 84dcc64aefabcdefghebcf7762752xx"
以下是我的代码在MS-ACESS中写的VBA,
Function GetAuthorization()
Dim objCurlHttp As Object
Dim strResult As String
Dim varReqToken As Variant
Dim strWebServiceUrl As String
Dim strOwnerKey As String
Dim strQry As String
strWebServiceUrl = "https://app.mysite.fr/api/v1/societe/11111111"
strOwnerKey = "84dcc64aefabcdefghebcf776275xx"
Set objCurlHttp = CreateObject("MSXML2.serverXMLHTTP")
With objCurlHttp
.Open "GET", strWebServiceUrl, False
.SetRequestHeader "cache-control", "no-cache"
.SetRequestHeader "Content-type", "application/json"
.SetRequestHeader "Content-type", "Accept"
.SetRequestHeader "Authorization", "Bearer " + strOwnerKey
.Send
strResult = .ResponseText
Debug.Print strResult
End With
Set objCurlHttp = Nothing
End Function
此结果是
? getAuthorization() 未经授权
非常感谢。
I need help to get authorization to connect to an API. The command line given is
curl -X GET "https://app.mysite.fr/api/v1/societe/11111111" -H "Authorization: Bearer 84dcc64aefabcdefghebcf7762752xx"
Below is my code written in VBA in ms-access
Function GetAuthorization()
Dim objCurlHttp As Object
Dim strResult As String
Dim varReqToken As Variant
Dim strWebServiceUrl As String
Dim strOwnerKey As String
Dim strQry As String
strWebServiceUrl = "https://app.mysite.fr/api/v1/societe/11111111"
strOwnerKey = "84dcc64aefabcdefghebcf776275xx"
Set objCurlHttp = CreateObject("MSXML2.serverXMLHTTP")
With objCurlHttp
.Open "GET", strWebServiceUrl, False
.SetRequestHeader "cache-control", "no-cache"
.SetRequestHeader "Content-type", "application/json"
.SetRequestHeader "Content-type", "Accept"
.SetRequestHeader "Authorization", "Bearer " + strOwnerKey
.Send
strResult = .ResponseText
Debug.Print strResult
End With
Set objCurlHttp = Nothing
End Function
This result is
? GetAuthorization()
Unauthorized
Thanks a lot in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有透露该文档,但我严重怀疑它显示了 Accept 如图所示。所以尝试:
You don't reveal the documentation, but I seriously doubt that it states the Accept header as shown. So try: