使用VBA连接到API

发布于 2025-02-05 11:44:36 字数 1246 浏览 4 评论 0原文

我需要帮助才能获得授权才能连接到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听不够的曲调 2025-02-12 11:44:36

您没有透露该文档,但我严重怀疑它显示了 Accept 如图所示。所以尝试:

        .Open "GET", strWebServiceUrl, False
        
        .SetRequestHeader "Content-type", "application/json"
        .SetRequestHeader "Accept", "application/json"
        .SetRequestHeader "Authorization", "Bearer " + strOwnerKey

You don't reveal the documentation, but I seriously doubt that it states the Accept header as shown. So try:

        .Open "GET", strWebServiceUrl, False
        
        .SetRequestHeader "Content-type", "application/json"
        .SetRequestHeader "Accept", "application/json"
        .SetRequestHeader "Authorization", "Bearer " + strOwnerKey
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文