卷曲没有在PHP中响应

时间:2015-08-06 09:19:22

标签: php curl

我正在使用当前货币汇率,所以我确实使用了雅虎财务链接,但在卷曲中我没有得到任何答复 我试图设置内容类型,但它不起作用请帮助我

$url=urlencode("http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ('USDUSD','USDEUR','USDGBP','USDINR','USDAED','INRINR','INREUR','INRGBP','INRAED','INRUSD')&env=store://datatables.org/alltableswithkeys");

        $request = curl_init(); 
        $timeOut = 0; 
        curl_setopt ($request, CURLOPT_URL, $url); 
        curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); 
        curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut); 
        curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-type:  application/xml'));

        $response = curl_exec($request); 

        print_r(curl_getinfo($request));
        curl_close($request);

获得回复

Array
(
    [url] => HTTP://http%3A%2F%2Fquery.yahooapis.com%2Fv1%2Fpublic%2Fyql%3Fq%3Dselect+%2A+from+yahoo.finance.xchange+where+pair+in+%28%27USDUSD%27%2C%27USDEUR%27%2C%27USDGBP%27%2C%27USDINR%27%2C%27USDAED%27%2C%27INRINR%27%2C%27INREUR%27%2C%27INRGBP%27%2C%27INRAED%27%2C%27INRUSD%27%29%26env%3Dstore%3A%2F%2Fdatatables.org%2Falltableswithkeys/
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0
    [namelookup_time] => 0
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 
    [certinfo] => Array
        (
        )

    [primary_port] => 0
    [local_ip] => 
    [local_port] => 0
)

1 个答案:

答案 0 :(得分:3)

你正在对网址进行urlencoding,这会破坏网址。尝试

$url = "http://query.yahooapis.com/v1/public/yql?q=";
$url .= urlencode("select * from yahoo.finance.xchange where pair in ('USDUSD','USDEUR','USDGBP','USDINR','USDAED','INRINR','INREUR','INRGBP','INRAED','INRUSD')");
$url .= "&env=";
$url .= urlencode("store://datatables.org/alltableswithkeys"));

修改

首先没有看到第二个GET参数,更新了代码。