CURL,请求没有响应.这个是一开始代码>
$url=urlencode("http://query.yahooapis.com/v1/public/yql?q=select id,Rate from yahoo.finance.xchange where pair in ("CNYJPY")&env=store://datatables.org/alltableswithkeys&format=json");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
print_r(curl_getinfo($ch));
curl_close($ch);CURL这个是修改后代码.
$url = "http://query.yahooapis.com/v1/public/yql?q=";
$url .= urlencode("select id,Rate from yahoo.finance.xchange where pair in ('CNYJPY')");
$url .= "&env=";
$url .= urlencode("store://datatables.org/alltableswithkeys");
$url .= "&format=";
$url .= urlencode("json");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res=curl_exec($ch);
curl_close($ch);这个是个人心得,主要原因是url的编码问题,带参数不能一起编码,要给参数分开编码,这样浏览器就不会认识URL.