@@ -693,17 +693,21 @@ cookies automatically.
693
693
694
694
You can either :ref: `send cookies with the BrowserKit component <component-browserkit-sending-cookies >`,
695
695
which integrates seamlessly with the HttpClient component, or manually setting
696
- the `` Cookie `` HTTP header as follows::
696
+ ` the Cookie HTTP request header `_ as follows::
697
697
698
698
use Symfony\Component\HttpClient\HttpClient;
699
699
use Symfony\Component\HttpFoundation\Cookie;
700
700
701
701
$client = HttpClient::create([
702
702
'headers' => [
703
- 'Cookie' => new Cookie('flavor', 'chocolate', strtotime('+1 day')),
703
+ // set one cookie as a name=value pair
704
+ 'Cookie' => 'flavor=chocolate',
704
705
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('...')),
707
711
],
708
712
]);
709
713
@@ -2089,3 +2093,4 @@ test it in a real application::
2089
2093
.. _`EventSource` : https://www.w3.org/TR/eventsource/#eventsource
2090
2094
.. _`idempotent method` : https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods
2091
2095
.. _`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