rest - Using PHP's CURL to store API's JSON to variable -
i'm trying store info exposed next url in php variable ($curl_response) farther manipulation, current code not executing properly. i've copied/pasted info exposed in next url body of html file , have tried running below script on html file, , curl works properly. i'm guessing issue has getting response correctly particular site. perhaps there curl alternative i'm overlooking.
http://tdm.prod.obanyc.com/api/pullouts/agency/mtabc/list
thoughts?
<?php $ch = curl_init("http://tdm.prod.obanyc.com/api/pullouts/agency/mtabc/list"); curl_setopt($ch, curlopt_returntransfer, true); $curl_response = curl_exec($ch); if ($curl_response === false) { $info = curl_getinfo($ch); curl_close($ch); die('error occured during curl exec. additioanl info: ' . var_export($info)); } else echo $curl_response ; curl_close($ch); ?> the debugging output is:
array ( 'url' => '', 'content_type' => null, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 63.145232, 'namelookup_time' => 0.006015, 'connect_time' => 0, 'pretransfer_time' => 0, 'size_upload' => 0, 'size_download' => 0, 'speed_download' => 0, 'speed_upload' => 0, 'download_content_length' => -1, 'upload_content_length' => -1, 'starttransfer_time' => 0, 'redirect_time' => 0, 'certinfo' => array ( ), 'primary_ip' => '10.137.36.11', 'primary_port' => 80, 'local_ip' => '', 'local_port' => 0, 'redirect_url' => '', )error occured during curl exec. additioanl info:
is else statement in question same way in code? if yes, start fixing else statement
change
else $curl_response ; to
else { $curl_response; // might want echo $curl_response or store or it. in it's current state nothing. } php rest curl
No comments:
Post a Comment