Php 卷曲到有头部问题的口吻
我正在尝试在guzzle上设置授权标题。我的请求已成功使用以下CURL代码:Php 卷曲到有头部问题的口吻,php,curl,guzzle,Php,Curl,Guzzle,我正在尝试在guzzle上设置授权标题。我的请求已成功使用以下CURL代码: function callApi($url,$accesstoken) { $headr = array(); $headr[] = 'Authorization:Bearer '.$accesstoken; //cURL starts $crl = curl_init(); curl_setopt($crl, CURLOPT_URL, $url); curl_set
function callApi($url,$accesstoken)
{
$headr = array();
$headr[] = 'Authorization:Bearer '.$accesstoken;
//cURL starts
$crl = curl_init();
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($crl, CURLOPT_HTTPGET,true);
$reply = curl_exec($crl);
//error handling for cURL
if ($reply === false) {
print_r('Curl error: ' . curl_error($crl));
return false;
}
curl_close($crl);
return $reply;
}
我怎么会得到一个401和这个狂饮的代码。我尝试了很多不同的方法来设置头球,但没有运气
public function __construct()
{
$this->config = \Config::get('services.******');
$this->client = new Client([
'base_uri' => 'https://*******/' . $this->config['merchant_id']
]);
}
public function getInventoryItems()
{
$response = $this->client->get('items', [
'headers' => [
'Authorization' => 'Bearer' . $this->config['token']
]
]);
return json_decode($response->getBody());
}
应该是
'Authorization' => 'Bearer ' . $this->config['token']
呃,无可奉告。谢谢,我想我还需要一双眼睛。
'Authorization' => 'Bearer ' . $this->config['token']