A
A
Alexander Savenko2021-01-29 22:55:07
HTTP Cookies
Alexander Savenko, 2021-01-29 22:55:07

Why don't cookies received via Chrome work in Guzzle?

Hello!
In the browser I see a request to the server and it can be copied as curl. If I run it in the console, then I get the data,
and if I substitute Cookie in Guzzle, then I get an error that authorization is needed. Sample data:

curl 'https://test.ru' \
    -H 'Connection: keep-alive' \
    -H $'Cookie: WMONID=nRiQPgfdbrq; EUOBGSPNSESSIONID=pc1PrDd8VGeeVvONfQSptl7fIOxBla_tcfvJ6GqViXWeLBGojsP\u00211681227827\u00211177731283' \
    --data-raw 'cmd=ServiceOrderModelSearchCmd&MODEL=SM-T295NZKASER&ASC_CODE=00062555555' \


What does the $ symbol after -H mean (the request does not work without the $ symbol)?
In guzzle, I substitute the data as:

$domain = 'test.ru';
$values = [
'WMONID' => 'nRiQPgfdbrq',
'EUOBGSPNSESSIONID'=>'pc1PrDd8VGeeVvONfQSptl7fIOxBla_tcfvJ6GqViXWeLBGojsP\u00211681227827\u00211177731283'
];

$cookieJar = \GuzzleHttp\Cookie\CookieJar::fromArray($values, $domain);

$client = new \GuzzleHttp\Client([
    'base_uri' => 'https://test.ru',
]);

$response = $client->get('/endpoint',[
  'cookies'  => $cookieJar 
]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question