2016-06-03 20 views
0

Ich versuche, das Ergebnis von dieser Website mit cURL zu erhalten. Es gibt nur weiße Seite nicht mit dem Download-Link zurück. Was ist falsch mit meinem Code?cURL Postformular und das Ergebnis

Dies ist meine Codes

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

?> 

Thx

+0

Warum setzen Sie 'CURLOPT_POST' auf die Anzahl der Felder? Es soll "wahr" oder "falsch" sein. – Barmar

+0

Überprüfen Sie '$ result', um zu sehen, ob die Anfrage erfolgreich war. – Barmar

+0

@Barmar Ich versuche, curloprt_post 1 oder 0 zu ändern, und gebe das $ -Ergebnis zurück. es gibt Nummer 1 nicht den Downloadlink zurück. was genau das Problem? –

Antwort

0

Sie müssen möglicherweise in den Körper Ihrer POST-Anfrage die Daten kodieren url. Also statt:

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

würden Sie haben:

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

was meinst du? Kannst du den kompletten Code posten? So kann ich analysieren, was mit meinem Code nicht stimmt. weil ich immer noch leerresultat bekomme. –

+0

Sie müssen 'urlencode()' nicht aufrufen. cURL führt dies automatisch durch, wenn es das Datenarray zum Posten serialisiert. – Barmar