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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?