Guzzle 5.3: impossible for POST JSON body if it is more than ~ 1 MB

I am using Guzzle 5.3 through Guzzle Services (via https://github.com/ticketevolution/ticketevolution-php ) to try to POST to the API endpoint with a JSON body that includes base64 encoded PDF. When the body is less than ~ 1 MB, it works fine. When the body is larger, it seems that the body never sets off.

I tested this with and without the Expect: 100 header and it doesn't seem to matter.

I tested with Transfer-Encoding: chunked, but since the API needs a full POST body for authentication using chunked, it does not work.

We tested with and without load balancing between the client and application servers.

Of all that we can say, the body simply does not send when it is more than ~ 1 MB.

Does anyone have any ideas on how to get Guzzle 5.3 to send a body, even if it's more than 1 MB?

Below is the log output

[2015-09-01 16:15:43] TEvoAPIClientLogger.CRITICAL: >>>>>>>> POST /v9/orders/2100732/deliver_etickets HTTP/1.1 Host: api.ticketevolution.com User-Agent: ticketevolution-php/3.0.0dev Guzzle/5.3.0 curl/7.44.0 PHP/5.5.28 Content-Type: application/json Content-Length: 1387036 X-Token: b47dsd8c0ab80a1e2bc24sc341415a2f X-Signature: SwBOkdUOqG3SDtjVwi2etosdP+gppwuV5dCq8yMw9lM= {"etickets":[{"item_id":1513651,"eticket":"JVBERi0xLjQKJeLjz9MKNCAwIG9iaiBbXQplbโ€ฆ [a whole lot of base64 snipped] โ€ฆNwolJUVPRgo="}]} <<<<<<<< -------- cURL error 52: Empty reply from server 
0
php guzzle
source share
1 answer

Performing the same problem, a bit of debugging led to completion in GuzzleHttp\Ring\Client\CurlFactory::applyBody() , and then this fixed the problem for me:

Setting default client configuration

 $client = new \GuzzleHttp\Client([ 'defaults' => [ 'config' => [ 'curl' => [ 'body_as_string' => true, ], ], ], ]); 

Configuring when prompted

 $client->post('https://example.com', [ 'json' => $json, 'config' => [ 'curl' => [ 'body_as_string' => true, ], ], ]); 

Rewinding a previously loaded actual content stream

Since I receive content from a remote server, this article in Matt Downling's article helped me find out that I need to rewind the actual one before using it as part of the multipart/form-data request:

 $response->getBody()->seek(0); 
+3
source share

All Articles