Skip to content

Commit 793db1e

Browse files
committed
Merge branch '6.4' into 7.2
* 6.4: Tweak Update http_client.rst [Form] Adding `DataPart` to manually set the `Content-Type`
2 parents 63a198a + 8579d1c commit 793db1e

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

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

0 commit comments

Comments
 (0)