2013-03-29 3 views
1

"file_get_contents"및 "cURL"에 문제가 있습니다. 내가 이것을 할 때 :파일 가져 오기 내용 및 cURL 오류

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] 

그런 다음 나는이 같은 CURL 시도 :

$myFile = 'http://example.com/asset_compress/assets/get/bbb.js?file%5B0%5D=myfile.js'; 
$a=file_get_contents($myFile); 

나는이 오류가

$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); 

을 그리고 난이 오류를 얻을 :

404 Not Found: The resource requested could not be found on this server! 

하지만 내 b에 http://example.com/asset_compress/assets/get/bbb.js?file%5B0%5D=myfile.js을 쓸 때 rowser의 주소 표시 줄, 나는 파일을 완벽하게 얻는다. 브라우저의 헤더는 다음과 같이이다 :

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을 의심하고 내가 이것을 할 때, 나는 완벽하게 출력을 얻을 : 나는 컬을 할 때

$d1 = file_get_contents("http://www.yahoo.com"); 
print_r($d1); 

나는 404 오류가 발생합니다. 브라우저 요청으로 200 점을 얻었음에도 불구하고 404가 표시되는 이유를 어떻게 진단 할 수 있습니까?

+0

'$ myFile'을'url_decode' 시도하십시오. – Crisp

+0

웹 서버에서 오는 HTTP 요청을 방해하는 프록시가있을 수 있습니다. – Barmar

+0

'curl_setopt'에'CURLOPT_AUTOREFERER'이 있습니까? 'curl_setopt ($ curl, CURLOPT_VERBOSE, true);를 설정하고 cli :'php script_with_curl.php'로 실행하십시오. – mkjasinski

답변

0

로컬 컴퓨터에서 호스팅됩니까? 아니면 어디에서? 내 호스트가 내 요청을 차단하는 라인 아래로 ISP로 결정되는 비슷한 문제가있었습니다.

+0

파일이 저장됩니다. 원격 웹 서버에서. – trante

+0

아마도 웹 호스트가 문제의 URL에 대한 traceroute를 서버에서 직접 실행할 수 있는지, 그리고 그 홉이 얼마나 죽었는지 확인하십시오. – vashavoc

+0

내가 잘못 말하면 죄송합니다. * MyController.php *와 * bbb.js * 파일은 모두 동일한 서버 및 동일한 도메인에 있습니다. – trante