2016-06-03 5 views
0

나는 cURL을 사용하여이 사이트에서 결과를 얻으려고합니다. 다운로드 링크가없는 흰색 페이지 만 반환합니다. 내 코드가 잘못된 이유는 무엇입니까?cURL 게시 양식과 결과를 반환

이 내 코드

<?php 
// Define URL where the form resides 
$form_url = "http://www.tusfiles.net/83gjiu9h49nw"; 

// This is the data to POST to the form. The KEY of the array is the name of the field. The value is the value posted. 
$data_to_post = array(); 
$data_to_post['op'] = 'download2'; 
$data_to_post['id'] = '83gjiu9h49nw'; 
$data_to_post['rand'] = 'utpaxiqp4ocv6krspq5geslurstt7z3bmvt5eqa'; 
$data_to_post['referer'] = ''; 
$data_to_post['method_free'] = ''; 
$data_to_post['method_premium'] = ''; 
$data_to_post['submit'] = 'Direct download link'; 

// Initialize cURL 
$curl = curl_init(); 

// Set the options 

curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); 

curl_setopt($curl,CURLOPT_URL, $form_url); 

// This sets the number of fields to post 
curl_setopt($curl,CURLOPT_POST, sizeof($data_to_post)); 

// This is the fields to post in the form of an array. 
curl_setopt($curl,CURLOPT_POSTFIELDS, $data_to_post); 

//execute the post 
$result = curl_exec($curl); 

//close the connection 
curl_close($curl); 

?> 

당신은 당신의 POST 요청의 본문에 인코딩에게 데이터를 URL에해야 할 수도 들으

+0

왜 필드의 수에'CURLOPT_POST'를 설정합니까? '사실'또는 '거짓'이라고 가정합니다. – Barmar

+0

요청이 성공했는지 확인하려면'$ result'를 확인하십시오. – Barmar

+0

@Barmar curloprt_post 1 또는 0을 변경하려고 시도하고 $ 결과를 표시합니다. 다운로드 링크가 아니라 1을 반환합니다. 무슨 문제 야? –

답변

0

입니다. 그래서 대신 :

$data_to_post['submit'] = 'Direct download link'; 

당신 거라고 :

$data_to_post['submit'] = urlencode('Direct download link'); 
+0

당신은 무엇을 의미합니까? 전체 코드를 게시 할 수 있습니까? 그래서 나는 내 코드에 무슨 문제가 있는지 분석 할 수있다. 왜냐하면, 나는 여전히 빈 결과를 얻고 있기 때문입니다. –

+0

당신은'urlencode()'를 부를 필요가 없습니다. cURL은 게시 할 데이터 배열을 직렬화 할 때 자동으로이 작업을 수행합니다. – Barmar

관련 문제