如何使用JSON进行get调用并检索数据

时间:2015-09-20 12:17:22

标签: php json

我正在尝试按照RFC规范中的说明从“证书透明度日志”known logs here

中检索数据

说明要做一个JSON调用,但我似乎没有任何成功..我实际上根本没有得到任何数据响应。

以下是我要遵循的指南: https://tools.ietf.org/html/rfc6962#section-4.6

这是我正在使用的PHP代码

<?php

$data = array("start" => "1", "end" => "10");                                                                    
$data_string = json_encode($data);                                                                                   

$ch = curl_init('https://ct.googleapis.com/pilot/ct/v1/get-entries');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       
);                                                                                                                   

$result = curl_exec($ch);

var_dump(json_decode($result, true));
?>

1 个答案:

答案 0 :(得分:0)

我连接的服务安装了SSL证书,但没有响应我的请求。禁用信任验证是解决方案。我将此添加到CURL选项 CURLOPT_SSL_VERIFYPEER =&gt;假