Closed
Description
HttpClient is used for sending HTTP requests, but not for responding to HTTP requests, so the following lines are invalid.
'headers' => [
'Cookie' => new Cookie('flavor', 'chocolate', strtotime('+1 day')),
// you can also pass the cookie contents as a string
'Cookie' => 'flavor=chocolate; expires=Sat, 11 Feb 2023 12:18:13 GMT; Max-Age=86400; path=/'
],
PHP parses and populates the $_COOKIE array as follows which is wrong:
$_COOKIE = [
"flavor" => "chocolate",
"expires" => "Sat, 08 Jun 2024 08:34:15 GMT",
"Max-Age" => "86400",
"path" => "/",
"httponly" => "",
"samesite" => "lax",
];
So, one of the variances is to use the following syntax:
'headers' => [
'Cookie' => 'foo=bar;baz=zap',
// Or an encoded format
'Cookie' => sprintf("%s=%s", 'foo', rawurlencode('bar'))
],
See: