Skip to content

Commit aa84c7d

Browse files
[Form] Adding DataPart to manually set the Content-Type
Page: https://symfony.com/doc/6.4/http_client.html#uploading-data
1 parent 621b57b commit aa84c7d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

http_client.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,15 @@ of the opened file, but you can configure both with the PHP streaming configurat
665665
$formData->getParts(); // Returns two instances of TextPart both
666666
// with the name "array_field"
667667

668+
Usually, the ``Content-Type`` of each form's part is detected automatically. However,
669+
you can override it by passing a ``DataPart``::
670+
671+
use Symfony\Component\Mime\Part\DataPart;
672+
673+
$formData = new FormDataPart([
674+
['json_data' => new DataPart(json_encode($json), null, 'application/json')]
675+
];
676+
668677
By default, HttpClient streams the body contents when uploading them. This might
669678
not work with all servers, resulting in HTTP status code 411 ("Length Required")
670679
because there is no ``Content-Length`` header. The solution is to turn the body

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy