Skip to content

Commit 24dfe8a

Browse files
committed
minor #20960 [HttpClient] Adding DataPart to manually set the Content-Type (ThomasLandauer)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [HttpClient] Adding `DataPart` to manually set the `Content-Type` Page: https://symfony.com/doc/6.4/http_client.html#uploading-data Commits ------- f8ae9b9 Update http_client.rst aa84c7d [Form] Adding `DataPart` to manually set the `Content-Type`
2 parents 352ab1f + f8ae9b9 commit 24dfe8a

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
@@ -672,6 +672,15 @@ of the opened file, but you can configure both with the PHP streaming configurat
672672
$formData->getParts(); // Returns two instances of TextPart both
673673
// with the name "array_field"
674674

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

0 commit comments

Comments
 (0)