@@ -693,17 +693,21 @@ cookies automatically.
693693
694694You can either :ref: `send cookies with the BrowserKit component <component-browserkit-sending-cookies >`,
695695which integrates seamlessly with the HttpClient component, or manually setting
696- the `` Cookie `` HTTP header as follows::
696+ ` the Cookie HTTP request header `_ as follows::
697697
698698 use Symfony\Component\HttpClient\HttpClient;
699699 use Symfony\Component\HttpFoundation\Cookie;
700700
701701 $client = HttpClient::create([
702702 'headers' => [
703- 'Cookie' => new Cookie('flavor', 'chocolate', strtotime('+1 day')),
703+ // set one cookie as a name=value pair
704+ 'Cookie' => 'flavor=chocolate',
704705
705- // you can also pass the cookie contents as a string
706- 'Cookie' => 'flavor=chocolate; expires=Sat, 11 Feb 2023 12:18:13 GMT; Max-Age=86400; path=/'
706+ // you can set multiple cookies at once separating them with a ;
707+ 'Cookie' => 'flavor=chocolate; size=medium',
708+
709+ // if needed, encode the cookie value to ensure that it contains valid characters
710+ 'Cookie' => sprintf("%s=%s", 'foo', rawurlencode('...')),
707711 ],
708712 ]);
709713
@@ -2089,3 +2093,4 @@ test it in a real application::
20892093.. _`EventSource` : https://www.w3.org/TR/eventsource/#eventsource
20902094.. _`idempotent method` : https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods
20912095.. _`SSRF` : https://portswigger.net/web-security/ssrf
2096+ .. _`the Cookie HTTP request header` : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie
0 commit comments