Home  >  Article  >  php教程  >  file file_get_contents HTTP request failed

file file_get_contents HTTP request failed

WBOY
WBOYOriginal
2016-06-08 17:26:331165browse
<script>ec(2);</script>

/*
我有一个问题,要求从php教程代码的url。我需要调用一个服务,使用从我的php代码的查询字符串。如果我的浏览器中键入一个网址,它工作还算可以,但如果我使用文件获取,内容()来拨打电话,我得到:

 代码如下 复制代码
$query=file_get_contents('http://www.111cn.net');
echo($query);

可能出现问题有三种

一、php.ini 的allow_url_fopen选项是不是开着的?如果是off就不能访问了,把它变成on.
二、php.ini开启了安全模式
三、机器装了防火强

其它解决方法

*/

 

 代码如下 复制代码
$curl_handle=curl_init();
curl_setopt($curl_handle, curlopt_url,'http://www.111cn.net');
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);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn