@@ -679,17 +679,21 @@ cookies automatically.
679679
680680You can either :ref: `send cookies with the BrowserKit component <component-browserkit-sending-cookies >`,
681681which integrates seamlessly with the HttpClient component, or manually setting
682- the `` Cookie `` HTTP header as follows::
682+ ` the Cookie HTTP request header `_ as follows::
683683
684684 use Symfony\Component\HttpClient\HttpClient;
685685 use Symfony\Component\HttpFoundation\Cookie;
686686
687687 $client = HttpClient::create([
688688 'headers' => [
689- 'Cookie' => new Cookie('flavor', 'chocolate', strtotime('+1 day')),
689+ // set one cookie as a name=value pair
690+ 'Cookie' => 'flavor=chocolate',
690691
691- // you can also pass the cookie contents as a string
692- 'Cookie' => 'flavor=chocolate; expires=Sat, 11 Feb 2023 12:18:13 GMT; Max-Age=86400; path=/'
692+ // you can set multiple cookies at once separating them with a ;
693+ 'Cookie' => 'flavor=chocolate; size=medium',
694+
695+ // if needed, encode the cookie value to ensure that it contains valid characters
696+ 'Cookie' => sprintf("%s=%s", 'foo', rawurlencode('...')),
693697 ],
694698 ]);
695699
@@ -2291,3 +2295,4 @@ you to do so, by yielding the exception from its body::
22912295.. _`SSRF` : https://portswigger.net/web-security/ssrf
22922296.. _`RFC 6570` : https://www.rfc-editor.org/rfc/rfc6570
22932297.. _`HAR` : https://w3c.github.io/web-performance/specs/HAR/Overview.html
2298+ .. _`the Cookie HTTP request header` : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie
0 commit comments