@@ -679,17 +679,21 @@ cookies automatically.
679
679
680
680
You can either :ref: `send cookies with the BrowserKit component <component-browserkit-sending-cookies >`,
681
681
which integrates seamlessly with the HttpClient component, or manually setting
682
- the `` Cookie `` HTTP header as follows::
682
+ ` the Cookie HTTP request header `_ as follows::
683
683
684
684
use Symfony\Component\HttpClient\HttpClient;
685
685
use Symfony\Component\HttpFoundation\Cookie;
686
686
687
687
$client = HttpClient::create([
688
688
'headers' => [
689
- 'Cookie' => new Cookie('flavor', 'chocolate', strtotime('+1 day')),
689
+ // set one cookie as a name=value pair
690
+ 'Cookie' => 'flavor=chocolate',
690
691
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('...')),
693
697
],
694
698
]);
695
699
@@ -2291,3 +2295,4 @@ you to do so, by yielding the exception from its body::
2291
2295
.. _`SSRF` : https://portswigger.net/web-security/ssrf
2292
2296
.. _`RFC 6570` : https://www.rfc-editor.org/rfc/rfc6570
2293
2297
.. _`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