@@ -687,17 +687,21 @@ cookies automatically.
687
687
688
688
You can either :ref: `send cookies with the BrowserKit component <component-browserkit-sending-cookies >`,
689
689
which integrates seamlessly with the HttpClient component, or manually setting
690
- the `` Cookie `` HTTP header as follows::
690
+ ` the Cookie HTTP request header `_ as follows::
691
691
692
692
use Symfony\Component\HttpClient\HttpClient;
693
693
use Symfony\Component\HttpFoundation\Cookie;
694
694
695
695
$client = HttpClient::create([
696
696
'headers' => [
697
- 'Cookie' => new Cookie('flavor', 'chocolate', strtotime('+1 day')),
697
+ // set one cookie as a name=value pair
698
+ 'Cookie' => 'flavor=chocolate',
698
699
699
- // you can also pass the cookie contents as a string
700
- 'Cookie' => 'flavor=chocolate; expires=Sat, 11 Feb 2023 12:18:13 GMT; Max-Age=86400; path=/'
700
+ // you can set multiple cookies at once separating them with a ;
701
+ 'Cookie' => 'flavor=chocolate; size=medium',
702
+
703
+ // if needed, encode the cookie value to ensure that it contains valid characters
704
+ 'Cookie' => sprintf("%s=%s", 'foo', rawurlencode('...')),
701
705
],
702
706
]);
703
707
@@ -2360,3 +2364,4 @@ you to do so, by yielding the exception from its body::
2360
2364
.. _`SSRF` : https://portswigger.net/web-security/ssrf
2361
2365
.. _`RFC 6570` : https://www.rfc-editor.org/rfc/rfc6570
2362
2366
.. _`HAR` : https://w3c.github.io/web-performance/specs/HAR/Overview.html
2367
+ .. _`the Cookie HTTP request header` : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie
0 commit comments