我如何在机械化中模拟这个特定的帖子请求 [英] How do i simulate this particular post request in mechanize

查看:55
本文介绍了我如何在机械化中模拟这个特定的帖子请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

post请求如下.

 $bot->add_header(
'Host'=>'www.amazon.com',
'User-Agent'=>'application/json, text/javascript, */*',
'Accept'=>'application/json, text/javascript, */*',
'Accept Language'=>'en-us,en;q=0.5',
'Accept Encoding'=>'gzip, deflate',
'DNT'=>'1',
'Connection'=>'keep-alive',
'Content type'=>'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested with'=>'XMLHttpRequest',
'Referer'=>'https://www.amazon.com/gp/digital/fiona/manage?ie=UTF8&ref_=gno_yam_myk',
'Content length'=>'44',
'Cookie'=>'how do i put the cookie value');




Post parameters in my request :
sid-how do i get the session id.
new email-mailhost@mail.com

我的登录代码:

use WWW::Mechanize;
use HTTP::Cookies;
use HTML::Form;
use WWW::Mechanize::Link;
my $bot = WWW::Mechanize->new();
 $bot->agent_alias( 'Linux Mozilla' );
 # Create a cookie jar for the login credentials
 $bot->cookie_jar(         HTTP::Cookies->new(             file           => "cookies.txt",
                                              autosave       => 1,
                                              ignore_discard => 1,     ) );
 # Connect to the login page
 my $response = $bot->get( 'https://www.amazon.com/gp/css/homepage.html/' );
 # Get the login form. You might need to change the number.
 $bot->form_number(3);
 # Enter the login credentials.
 $bot->field( email => '' );
 $bot->field( password => '' );
 $response = $bot->click();
 #print $response->decoded_content;
 $bot->get( 'https://www.amazon.com/gp/yourstore/home?ie=UTF8&ref_=topnav_ys' );
 print $bot->content();


 $bot->post('https://www.amazon.com/gp/digital/fiona/du/add-whitelist.html/ref=kinw_myk_wl_add', [sid => 'id', email=> 'v2@d.com']); 

捕获的数据:

Host=www.amazon.com
User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept=application/json, text/javascript, */*
Accept-Language=en-us,en;q=0.5
Accept-Encoding=gzip, deflate
DNT=1
Connection=keep-alive
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With=XMLHttpRequest
Referer=https://www.amazon.com/gp/digital/fiona/manage?ie=UTF8&ref_=gno_yam_myk
Content-Length=39
Cookie=session-id-time=2082787201l; session-id
Pragma=no-cache
Cache-Control=no-cache
POSTDATA=sid=id&email=v%40d.com

错误信息-

Error POSTing https://www.amazon.com/gp/digital/fiona/du/add-whitelist.html/ref=
kinw_myk_wl_add: InternalServerError at logon.pl line 81

推荐答案

参见 WWW::Mechanize 中 >post.

$bot->post($url, [sid => 'id', email => 'v@d.com']);

这篇关于我如何在机械化中模拟这个特定的帖子请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆