相关
注释
尝试
问题
有没有一种方法可以在没有故意使请求失败的情况下获取授权的cookie?还是这个问题只是端点特定的,他们不希望我以这种方式访问他们的网站...
为什么我不能使用GET请求中的cookie?
代码
$client = new GuzzleHttp\Client(['cookies' => true]);
$formParams = [
'json' => [
'request' => [
'orderId' => 'XYZ123',
'emailId' => 'name@email.com'
]
],
'headers' => [
'Host' => 'secure2.homedepot.com',
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0',
'Accept' => 'application/json, text/plain, */*',
'Accept-Language' => 'en-US,en;q=0.5',
'Accept-Encoding' => 'gzip, deflate, br',
'Referer' => 'https://secure.website.com/order/view/tracking',
'Content-Type' => 'application/json;charset=utf-8',
'Content-Length' => '88',
'Connection' => 'keep-alive'
]
];
// first request will fail (403 Forbidden) ... but it gets the cookie
try {
$response = $this->client->request('POST', 'https://secure.website.com/order/guest/details', $formParams);
} catch (\Exception $e) {
Log::warning('first request failed ... but we wanted it too?');
}
// second request ... this works!
try {
// Log::warning(print_r($formParams, true));
$response = $this->client->request('POST', 'https://secure.website.com/order/guest/details', $formParams);
return $response;
} catch (\Exception $e) {
Log::warning($e->getMessage());
return false;
}