1
I have an application that needs to read external data, or another URL
, I’m doing this necessarily with Guzzle
, but when I convert to json
to mount the array with the data, it returns me null.
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
class salarioController extends Controller
{
public function index()
{
$client = new Client();
$response = $client->get('http://www.guiatrabalhista.com.br/guia/salario_minimo.htm');
$body = json_decode($response->getBody(), TRUE);
}
}
The result of $body
is empty.
That’s because the function
json_decode
expects a string JSON and you’re passing a document HTML:$response->getBody()
– NoobSaibot
The result of that address is html, and
json_decode
needs a string in the formatjson
=>json_decode ( string $json [, bool $assoc ] )
actually the result is null ...– novic
Recommend: https://answall.com/a/277196/99718 and also https://answall.com/q/277329/99718
– Valdeir Psr
BLZ, I’ll try it another way. I’ll try later , for now thanks a lot for the ringtones.
– Marcelo Bezerra
Good morning guys, consider SOLVED. I used guzzle + Goutte however it needs to be installed php7.1-xml package. it worked PERFEITAMETE. From then on just treat the array(). Thank you very much for the strength .. the code below is CORRECT and WORKING!!!!
– Marcelo Bezerra