首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文件获取内容和cURL错误

问文件获取内容和cURL错误
EN

Stack Overflow用户
提问于 2013-03-30 04:42:53
回答 1查看 700关注 0票数 1

我对"file_get_contents“和"cURL”有问题。当我这样做的时候:

代码语言:javascript
复制
$myFile = 'http://example.com/asset_compress/assets/get/bbb.js?file%5B0%5D=myfile.js';
$a=file_get_contents( $myFile );

我得到了这个错误:

代码语言:javascript
复制
Warning (2): file_get_contents
(http://example.com/asset_compress/assets/get/bbb.js?file%5B0%5D=myfile.js)
 [function.file-get-contents]: failed to open stream: 
    HTTP request failed! HTTP/1.0 404 Not Found
   [APP/Controller/MyController.php, line 1373]

然后我试着像这样卷曲:

代码语言:javascript
复制
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $myFile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_USERAGENT, $this->userAgent);
curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
curl_setopt($curl_handle, CURLOPT_AUTOREFERER, true);
$a = curl_exec($curl);
curl_close($curl);

我得到了这个错误:

代码语言:javascript
复制
404 Not Found: The resource requested could not be found on this server!

但是,当我在浏览器的地址栏中写入http://example.com/asset_compress/assets/get/bbb.js?file%5B0%5D=myfile.js时,我可以完美地获得该文件。浏览器的头部如下所示:

代码语言:javascript
复制
Request URL:http://example.com/asset_compress/assets/get/bbb.js?file%5B0%5D=myfile.js
Request Method:GET
Status Code:200 OK

Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:tr,en-US;q=0.8,en;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Host:example.com
User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.28 Safari/537.31

Query String Parameters
file[0]:myfile.js

Response Headers
Connection:close
Content-Length:15911
Content-Type:application/javascript; charset=UTF-8
Date:Fri, 29 Mar 2013 20:33:43 GMT
Server:Apache
X-Powered-By:PleskLin

我怀疑是file_get_contents,当我这样做的时候,我得到了完美的输出:

代码语言:javascript
复制
$d1 = file_get_contents("http://www.yahoo.com");
print_r($d1);

当我尝试cURL时,我得到404错误。我如何能更多地诊断为什么我得到404,尽管我从浏览器请求中得到200。

EN

回答 1

Stack Overflow用户

发布于 2013-03-30 05:59:14

这是托管在本地计算机上吗?或者在哪里?我遇到了一个类似的问题,我的主机决定作为ISP阻止我的请求。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15711102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档