doujiena0025 2015-01-19 09:53
浏览 62
已采纳

从服务器读取响应,作为文件下载

I am trying to read the response (json text) from server. But the server returns the response as a file which gets downloaded in my downloads directory.

url:-https://www.googleapis.com/freebase/v1/mqlread?query=%5B%7B%22id%22%3Anull%2C%22name%22%3Anull%2C%22type%22%3A%22%5C%2Fastronomy%5C%2Fplanet%22%7D%5D

I am using curl in my php code.

$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                            'Content-Type: application/json',
                                            'Connection: Keep-Alive'
                                            ));
        $response = json_decode(curl_exec($ch), true);
        curl_close($ch);

How can I read the data using php curl?

UPDATE: When I try to run the same code in online editors like http://phpassist.com/ then it reads the data and shows me the required output. So is there any additional configuration I need to make in XAMPP??

Tks

  • 写回答

1条回答 默认 最新

  • doutun1875 2015-01-19 10:09
    关注

    You need disable ssl certification or get ssl certification, the fastest way is:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog