我打电话给web服务返回json文本,该文件以一些垃圾在开始时结束“”“。任何帮助或指针赞赏。我对卷曲选项有点生疏,而且这些来自我使用的一些旧代码,自从我完成这样的工作以来已经有一段时间了。在json文本中获得一些有趣的charactres
当我通过浏览器调用Web服务时,我得到了很好的json文本,如下所示。我已经删除了一些值,只做几行
{ "values": [[1511596680,3],[1511596740,2],[1511596800,0],[1511596860,6],[1511596920,0],[1511596980,0],[1511597040,0],[1511597100,0],[1511597160,0],[1511603220,0],[1511603280,0],[1511603340,0],[1511603400,0],[1511603460,0],[1511603520,0],[1511603580,0],[1511603640,0],[1511603700,0],[1511603760,0],[1511603820,0]]}
当我通过一个充当包装的PHP页面调用时。我在它前面得到了一些废话,这阻止了php调用json_decode。被调用的URL与我以前在浏览器中调用Web服务的方式完全相同。
 { “值”:[[1511596680,3],[1511596740,2],[1511596800,0],[1511596860,6],[1511596920,0],[1511596980,0] [1511597040,0],[1511597100,0],[1511597160,0],[1511603220,0],[1511603280,0],[1511603340,0],[1511603400,0],[1511603460,0],[ 1511603520,0],[1511603580,0],[1511603640,0],[1511603700,0],[1511603760,0],[1511603820,0]]}
我的php代码调用web服务是如下。我不确定是否$ post_string为空是一个问题。 URL由在形式的URL字符串传递则params的?PARAM = VAL &参数2 =值2等
$contenttype = 'application/json';
$headers = array(
'Content-Type: ' . $contenttype,
'Content-Length: ' . strlen($post_string) /* this an empty string */
);
/* dump of headers
Array
(
[0] => Content-Type: application/json
[1] => Content-Length: 0
)
*/
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); // this is get */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if (is_array($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch); // this contains the crap at the start */
叶我这12个小时前解决自己。 –