0

我正在尝试从 cellid 和 LAC 获得经纬度。

我一直在尝试使用Trouble with Sending JSON object over POST to Google Gears中提到的这个脚本来完成这个

如果有任何或任何替代方式,您能否指出任何错误?

我正在粘贴下面的代码

<?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);    

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$param_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("application/json"));
$result=curl_exec($ch);
echo $result;
?>

这是更改后的代码(删除 url_encode)

4

1 回答 1

0

是的,您的代码与我的相同,唯一不同的是:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));

这段代码使用 CURL。您是否启用了 CURL 库?在大多数 PHP 安装中默认禁用它。

于 2011-06-16T16:10:51.493 回答