file file_get_contents HTTP request failed
我有一个问题,要求从php教程代码的url,我需要调用一个服务,使用从我的php代码的查询字符串,如果我的浏览器中键入一个网址,它工作还算可以,但如果我使用文件获取,内容()来拨打电话,我得到如下代码:
$query=file_get_contents('http://www.phprm.com');
echo($query);
可能出现问题有三种:
一、php.ini 的allow_url_fopen选项是不是开着的?如果是off就不能访问了,把它变成on.
二、php.ini开启了安全模式
三、机器装了防火强
其它解决方法,代码如下:
$curl_handle=curl_init(); curl_setopt($curl_handle, curlopt_url,'http://www.phprm.com'); curl_setopt($curl_handle, curlopt_connecttimeout, 2); curl_setopt($curl_handle, curlopt_returntransfer, 1); curl_setopt($curl_handle, curlopt_useragent, 'your application name'); $query = curl_exec($curl_handle); curl_close($curl_handle);
永久链接:http://www.phprm.com/develop/fs4344.html
转载随意!带上文章地址吧。