2011-12-01 30 views
0

可能重複:
cURL: Just trying to download a page只是想提交表單

我試圖提交this表格填寫不使用捲曲的領域。

我已經試過這樣:

<?php 

//set POST variables 
$url = 'http://www.tourism.verona.it/_vti_g1_srSf.aspx?rpstry=3_'; 

//open connection 
$ch = curl_init(); 

//set the url, number of POST vars, POST data 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_POST,0); 

//execute post 
$result = curl_exec($ch); 

//echo $result; 

//close connection 
curl_close($ch); 

但輸出是一樣的頁面(我預計,在之後顯示提交表單的頁面以及包含酒店的列表)。

+0

他們正在使用Post-Redirect-Get模式(PRG),因此您可以對生成的URL執行GET操作。 – Fenton

回答

1

我建議以下選項:

curl_setopt($ch,CURLOPT_POST, true); 
curl_setopt($ch,CURLOPT_POSTFIELDS, ""); 
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); //make sure apache is able to write 
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); //make sure apache is able to write 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 


CURLOPT_POST - to make a POST request 
CURLOPT_POSTFIELDS - to send POST data 
CURLOPT_FOLLOWLOCATION - for dealing with redirect. 

其他3有用與大多數網站和你更好地使用Cookie,然後試圖弄清楚爲什麼它不工作。

0

你確定你得到了所有需要設置的變量集?在他們的頁面上查看你需要填寫什麼樣的值以確保!

+0

我如何知道我需要填寫的值?但我真的需要給那個嗎?你知道我可以提交表格而不填充任何東西.. – ziiweb

+0

是的,你可以,但領域將被設置爲空,仍然在那裏。如果沒有他們,請求可能會失敗。 – lfxgroove

1
//set POST variables 
$url = 'http://www.tourism.verona.it/_vti_g1_srSf.aspx?rpstry=3_'; 

//open connection 
$ch = curl_init(); 

//set the url, number of POST vars, POST data 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_POST,1); 
curl_setopt($ch,CURLOPT_POSTFIELDS,'var1=value1;var2=value2'); 

//execute post 
$result = curl_exec($ch); 

//echo $result; 

//close connection 
curl_close($ch); 
1

即使您可以在不填寫詳細信息的情況下手動提交表單,這些字段仍會發送到服務器。

該字段設置,如果你不通過他們將無法檢查服務器端:

if (isset($_POST['srSearchForm:lstStruttura'])) { ... 

此外,他們使用的是POST-REDIRECT-GET模式後後您重定向一個GET網址。也許你可以做到最後得到http://www.tourism.verona.it/_vti_g1_srSr.aspx?rpstry=3_,因爲這規避了整個POST的需要。

+0

我試圖遵循這個例子:http://php.dzone.com/news/execute-http-post-using-php-cu,但我不知道$ last_name,$ first_name,$ title是創建/設置...任何幫助? – ziiweb