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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?