使用CURL设置承载令牌的正确方法 [英] Correct way to set Bearer token with CURL

查看:176
本文介绍了使用CURL设置承载令牌的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从API端点收到我的载体令牌,并设置以下内容:

I get my bearer token from an API end point and set the following:

$authorization = "Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274"

接下来我想使用CURL访问安全端点,但是我不确定如何或在哪里设置承载令牌。

Next I want to use CURL to access the secure endpoint however I am unsure on how or where to set the Bearer token.

我已尝试过但不起作用:

I have tried this but but it does not work:

 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $result = curl_exec($ch);
    curl_close($ch);
    return json_decode($result);

编辑:

,我应该使用承载令牌,如下所示: https://apigility.org/documentation/auth/authentication-oauth2

According to the documentation, I am supposed to be using the bearer token as such: https://apigility.org/documentation/auth/authentication-oauth2

GET /oauth/resource HTTP/1.1
Accept: application/json
Authorization: Bearer 907c762e069589c2cd2a229cdae7b8778caa9f07


推荐答案

取代:

$authorization = "Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274"


$ b b

与:

with:

$authorization = "Authorization: Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274";

以使其成为有效且有效的授权标头。

to make it a valid and working Authorization header.

这篇关于使用CURL设置承载令牌的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆