通过POST将JSON对象发送到Google Gears时遇到问题 [英] Trouble with Sending JSON object over POST to Google Gears
本文介绍了通过POST将JSON对象发送到Google Gears时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Google Gears提供了一个地理位置API,可以接收LAC-CELLId信息并提供lat-long数据。
此处详细介绍了API: Geolocation API
I我使用PHP。这是我写的代码:
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;
?>
得到的是JSON解析错误。
我做错了什么?
The response that I am getting is "JSON parsing error." What am I doing wrong?
推荐答案
不要urlencode。 application / json主体被永远编码。
Don't urlencode. application/json bodies are never urlencoded.
这篇关于通过POST将JSON对象发送到Google Gears时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文