I'm getting a weird encoding issue from a zf2 api call. I've verified the api is working internally, and the response it's supposed to send back comes from this in the api routine, which takes an image file and crops it:
$result = new ViewModel(array('output'=>$output, 'response'=>json_encode($response)));
A dump of $result before it's sent out looks like this:
[output] => json
[response] =>{"data":"http:\/\/dev.xxxxx.com\/tools\/files\/temporary_files\/f16da1965e4d0c487ae7692f4b51558b917c238e.1","status":"OK"}
But the actual response I'm getting back is like this:
^_<8b>^H^@^@^@^@^@^@^C%ÍM
^B!^T^@໸^Nß¹Â,:B<õI<82><8e><83>¾<82><88>î^Ðò[}o<96><80><80>ìNt¬B4(5^R>y*<93>F ¥ï<ö&¨÷:E.^U§ lG^_0^·¿³4 ¤7^ZU:Gå, 5~É*h©µ^K^Ú¸\^\rÉNl^RÐcþÖëÆ>_Id»'<83>^@^@^@
Here's how I'm calling the api, using curl:
$client = new Client($api_url);
$adapter = new Curl();
$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
$client->setAdapter($adapter);
$request = new Request();
$request->setUri($api_url);
$request->setMethod(\Zend\Http\Request::METHOD_POST);
$request->setContent($postString);
$response = $client->dispatch($request);
$responseContent = $response->getContent();
The part that looks encoded is a dump of $responseContent. Thinking it might be gzipped, because the response header says the content-type is gzip, I've tried various unzipping call on it, to no avail. What the heck is going on here?
The content is compressed with gzip. You need to use getBody(), and not getContent() on the response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With