只是试图提交表单 [英] just trying to submit a form
本文介绍了只是试图提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
cURL:只是尝试下载页面
我尝试提交此表单,但未填写任何字段cURL。
I'm trying to submit this form without filling any field using cURL.
我试过这个:
<?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);
但输出只是相同的页面(我预计在提交表单后显示的页面,
but the output is just the same page (I expected the page that is showed after submit the form and that contains a list of hotels).
推荐答案
我建议以下选项:
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适用于大多数网站,你最好使用cookies,它不工作。
the other 3 are useful with most of the websites and you better use cookies then trying to figure out why it doesn't work.
这篇关于只是试图提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文