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:

https://api.postcodes.io/postcodes/ox495nu

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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -