2016-06-22 2 views
0

cURL을 사용하여 다른 서버에서 zip 파일을 내 서버로 전송하려고합니다.php curl empity content

http://content.website.com/file_to_download.zip?nvb=20160622094506&nva=20160622095506&hash=089366e5fe3da46f9caf2 

내가 다른 웹 브라우저 또는 개인 세션에서이 URL을 서핑 만약 내가 문제없이 콘텐츠를 다운로드 할 수 있습니다 (요청하지 않는이 두 번째 서버 나에게 자격 증명으로도 매개 변수를 포함하는 URL을 제공합니다 인증 후 로그인),하지만 내 함수에 URL을 보내면 나는 empity 파일을 얻는다.

이 제 기능

function download ($zipUrl, $zipFilename){ 

    $ch = curl_init(); 
    $fp = fopen ($zipFilename, 'w+'); 
    $ch = curl_init($zipUrl); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
    curl_setopt($ch, CURLOPT_FILE, $fp); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2')); 
    curl_setopt($ch, CURLOPT_ENCODING, ""); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "nvb=20160622094506&nva=20160622095506&hash=089366e5fe3da46f9caf2"); 

    curl_exec($ch); 

    curl_close($ch); 
    fclose($fp);   



} 

뭐가 잘못입니까?

답변

0

curl_exec이 오류를 반환하면 curl_error로 해당 오류를 읽을 수 있습니다. 무슨 일이 일어나는지 분명히 이해할 수 있도록 http 코드 서버가 반환 한 것을 살펴보십시오.