I am working on building a rudimentary service which uses cURL to access some JSON-formatted data. From a php script I use cURL to make a request to a URL which is just a PHP script that outputs a JSON string via json_encode()-ing of an array of associative arrays (from database results). Visiting the page in the browser shows that the output is working:
[{"label":"Fun Fact","bits":"Did you know that the name \\"Floppy Deuce\\" is actually based on a handshake? True Story."},{"label":"Did You Know","bits":"Floppy Deuce offers competitive pricing for printing services. Moral of the story: If you need 300 bobblehead dolls that look like Gary Busey, we got you covered."},{"label":"F2 History","bits":"Floppy Deuce Co-Founder Chris Smola was a high school mathematics teacher for four years before becoming a full-time web developer. His new job is way more fun."}]
However, printing the curl_exec() data shows that only the first object in the array of objects has been returned:
[{"label":"Fun Fact","bits":"Did you know that the name \\"Floppy Deuce\\" is actually based on a handshake? True Story."}]
I have tried setting some of the cURL options as well as altering the cache and content-type headers in the output script, but nothing seems to work. I would prefer not to change to xml as it is more cumbersome to work with in PHP… =[
I’m sure I’m missing something blatantly obvious. Here is the curl code as it is now:
$handle = curl_init('http://f2.floppydeuce.com/feeds/f2bits');
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($handle, CURLOPT_POST, 1);
//this creates an array with one element which is an object
//$bits = json_decode(curl_exec($handle));
$bits = curl_exec($handle);
curl_close($handle);
and these are the headers I tried (after trying the transaction with none) in the output script. I’ve heard maybe text/json or text/plain might be the way to go?
header('Content-type: application/json');
header('Cache-Control: no-cache, must-revalidate');