nategood/httpful

UTF-8 response is not supported

Erfeniuses opened this issue · 2 comments

Greetings.

I'm trying to use this great tool for getting JSON from http source, but the reponse "Content-Type: text/json; charset=utf-8" and Httpful just crashes by "Unable to parse response as JSON". The content is UTF-8 and cURL can do this (CURLOPT_ENCODING] = "UTF-8").
The site is http://data.foli.fi/siri/vm

I think it's not about UTF-8.
The service responses with a header "encoding:gzip", so httpful have to unzip the contents.

Easy to fix:

$response = $this->prepare($api, 'get', $url)
    ->sendsJson()
    ->parseWith(function ($body) {
            $body = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($body));
            return json_decode($body, false);
    })
    ->send()->body;