Trouble with Sending JSON object over POST to Google Gears
Google Gears provides a geolocation API that can take LAC-CELLId information and supply lat-long data. The API is detailed here: Geolocation API I am using PHP. Here's the code that I wrote:
<?php
$urlstring="http://www.google.com/loc/json";
$ch=curl_init($urlstring);
$cell_towers = array();
$row=new stdClass();
$row->location_area_code=3311;
$row->mobile_network_code=71;
$row->cell_id=32751;
$row->mobile_country_code=404;
$cell_towers[]=$row;
$param = array(
'host'=> 'localhost',
'version' => '1.1.0',
'request_address' => true,
'cell_towers' => $cell_towers
);
$param_json=json_encode($param);
//echo $param_json."<br />";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,urlencode($param_json));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("application/jsonrequest"));
$result=curl_exec($ch);
echo $result;
?>
The response that I am getting is "JSON parsing er开发者_开发技巧ror." What am I doing wrong?
Don't urlencode. application/json bodies are never urlencoded.
Are you sure you have the correct application type. Their API uses: application/json
精彩评论