使用Laravel 5并尝试将一些数据从我的站点发送到另一个,这为我提供了REST API。但他们使用cookie作为授权。这一刻,我成功通过了auth。并坚持我应该如何通过POST方法将此cookie发送到API接口?这是我的清单。
提前完成。
P.S。所有事情都在控制器内部进行。
if (Cookie::get('amoauth') !== null) {
//COOKIE IS HERE
$client = new Client();
$newlead = $client->post('https://domain.amocrm.ru/private/api/v2/json/leads/set', [
'add' => [
'add/name' => 'TEST LEAD',
'add/date_create' => time(),
'add/last_modified' => time(),
'add/status_id' => '1',
'add/price' => 5000
]
]);
} else {
$client = new Client();
$auth = $client->post('https://domain.amocrm.ru/private/api/auth.php',[
'USER_LOGIN' => 'login',
'USER_HASH' => 'hash',
'type' => 'json'
]);
$auth = $auth->getHeaders('Set-Cookie');
Cookie::queue('amoauth', $auth, 15);
return redirect('/test');
}
现在它返回以下内容:
Client error: `POST https://domain.amocrm.ru/private/api/v2/json/leads/set` resulted in a `401 Unauthorized` response.
答案 0 :(得分:0)
找到解决方案:切换到ixudra/curl
。