【问题标题】:How to set Authorization HTTP header in Guzzle?如何在 Guzzle 中设置 Authorization HTTP 标头?
【发布时间】:2021-03-27 23:09:51
【问题描述】:

我想使用 Publons 的 API。他们提到了"Any other requests should include a token in the Authorization HTTP header and prefixed with 'Token'. 所以,我尝试在标题中设置Token。这是我的代码


$client = new Client([
            'base_uri' => "https://publons.com/api/v2/academic/",
            'headers' => [
                'Token' => "MyToken"
            ]
        ]);

结果是{"detail":"Authentication credentials were not provided."}。我确保令牌是正确的,因为我已经在 Talend API Tester 上尝试过它并且工作正常。谁能帮我?哪里错了?

【问题讨论】:

    标签: php http-headers guzzle


    【解决方案1】:

    只是猜测,他们的文档中没有太多内容,但我想应该是这样的:

    $client = new Client([
                'base_uri' => "https://publons.com/api/v2/academic/",
                'headers' => [
                    'Authorization' => "Token{Your api token here}"
                ]
    ]);
    

    他们想要以“Token”为前缀的授权标头和令牌...

    另外this 的问题会给你更多的想法来处理你的案件。

    【讨论】:

    • 有效,key为Authorizations,value为Token MyToken
    猜你喜欢
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-07
    • 2018-07-03
    • 2020-10-25
    • 1970-01-01
    • 2012-01-17
    • 2017-11-30
    相关资源
    最近更新 更多