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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)