我有一个外部网站,这需要我a。登录b. post形式( 2-3动态参数)
我需要一个PHP脚本来自动执行此行为。例如,脚本应该首先使用用户名/密码登录,然后导航到URL并提交表单(使用动态参数)
我如何使用PHP来做同样的事情?
发布于 2013-05-17 11:08:16
我推荐使用这个类:
http://semlabs.co.uk/journal/object-oriented-curl-class-with-multi-threading
它将是这样的:
$c = new CURLRequest();
$c->retry = 2;
$c->get( $url, $this->curlOpts );
$url = 'https://secure.login.co.uk/';
$opts = array(
CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
CURLOPT_COOKIEFILE => 'anc.tmp',
CURLOPT_COOKIEJAR => 'anc.tmp',
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_TIMEOUT => 120
);
$opts[CURLOPT_POSTFIELDS] = 'username=user&password=pass&submit=1';
$request = $c->get( $url, $opts );注意:有些网站要求您先下载登录页面才能设置cookie。
此外,您还需要在帖子字段中使用url_encode特殊字符。
https://stackoverflow.com/questions/16588073
复制相似问题