- Summary
- The option is used to easily upload JSON encoded data as thebody of a request. A Content-Type header of
application/json
will beadded if no Content-Type header is already present on the message. - Types
- Any PHP type that can be operated on by PHP's
json_encode()
function. - Default
- None
- Constant
- use GuzzleHttp\Middleware;
-
- // Grab the client's handler instance.
- $clientHandler = $client->getConfig('handler');
- $tapMiddleware = Middleware::tap(function ($request) {
- echo $request->getHeaderLine('Content-Type');
- // application/json
- echo $request->getBody();
- });
-
- $response = $client->request('PUT', '/put', [
- 'json' => ['foo' => 'bar'],
- ]);