php - Laravel - Guzzle not returning any data even though URL is correct -
i trying return json data third party api - http://postcodes.io/
. have in controller:
$client = new client(); $request = $client ->get('https://api.postcodes.io/postcodes/'.input::get('postcode')); $statuscode = $request->getstatuscode(); if ($statuscode >= 200 && $statuscode < 300) { $json = response::json($request); // returns json decoded array of data. }
i'm trying return postcode information such:
if dd($request)
, printed out, 200 status code no data associated it:
jsonresponse {#245 ▼ #jsonoptions: 0 #data: "{}" #callback: null #encodingoptions: 15 +headers: responseheaderbag {#242 ▶} #content: "{}" #version: "1.0" #statuscode: 200 #statustext: "ok" #charset: null }
any why happening appreciated.
what seeing raw response guzzle , needs formatted. simple way $response->getbody();
.
think of collection in laravel. when data back, in collection bunch of data may useful if want data run $user->tojson();
guzzle, if want strip out curl data, protocol info, headers, etc, want payload, or body. $response->getbody();
Comments
Post a Comment