狂饮HTTP-将Authorization标头直接添加到请求中 [英] Guzzle HTTP - add Authorization header directly into request

查看:114
本文介绍了狂饮HTTP-将Authorization标头直接添加到请求中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释如何在Guzzle中添加授权标头吗?我可以看到以下代码可用于添加用户名&密码,但在我的实例中,我只想添加Authorization标头本身

Can anyone explain how to add the Authorization Header within Guzzle? I can see the code below works for adding the username & password but in my instance I just want to add the Authorization header itself

$client->request('GET', '/get', ['auth' => ['username', 'password']

我要添加到GET请求中的基本授权标头:-

The Basic Authorization header I want to add to my GET request :-

Basic aGdkZQ1vOjBmNmFmYzdhMjhiMjcwZmE4YjEwOTQwMjc2NGQ3NDgxM2JhMjJkZjZlM2JlMzU5MTVlNGRkMTVlMGJlMWFiYmI=

推荐答案

从外观上看,您正在尝试使用API​​密钥.要获得所需的效果,只需将 null 作为用户名传入,如下所示.

From the looks of things, you are attempting to use an API key. To obtain your desired effect, simply pass null in as the username, like below.

$client->request(
    $method,
    $url,
    [
        'auth' => [
            null,
            $api_key
        ],
    ]
);

这篇关于狂饮HTTP-将Authorization标头直接添加到请求中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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