nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 298 forks source link

Corrupted Response when JSON value is a XML #292

Open contatolucascosta opened 3 years ago

contatolucascosta commented 3 years ago

Hi.

I found a issue, when the value/content of attribute of the response (application/json) is a XML. See this example, observe the attribute "route":

{
    "id": "60495986e195c92f356e1b6f",
    "applicationName": "api-onboarding-template",
    "route": "<cole-aqui-o-seu-xml/>"
}

The problem is because the response captured of Httpful is:

{
   "id":"60495986e195c92f356e1b6f",
   "applicationName":"api-onboarding-template",
   "route":""
}

See that content of attribute "route" was empty

My source code is:

$uri = "https://myendpoint...";
        $response= \Httpful\Request::get($uri)                  
                        ->addHeaders(array(
                                'X-Company-Id' => '01',
                                'X-Application-Id' => '01',
                                'X-User-Id' => '01',
                                'X-Trace-Id' => '01',
                                'Content-Type' => 'application/json'
                                ,'Authorization' => $_SESSION['tokenType'].' '.$_SESSION['token']                               
                        ))
                        ->send();
        echo "<br>$response->raw_body<br>";

Someone knows why it's happen this, and if it's possible to fix ? Please!

Best regards.