Skip to content

Commit 3f5c089

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: Tweak Update http_client.rst [Form] Adding `DataPart` to manually set the `Content-Type`
2 parents 9e20e29 + 6a1c1d1 commit 3f5c089

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

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

0 commit comments

Comments
 (0)