2012-05-18 18 views
1

發佈請求如下。如何在機械化模擬這個特定的發佈請求

$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 protected] 

我的代碼登錄:

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=> '[email protected]']); 

數據捕獲:

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 

錯誤MESSAGE-

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

回答

2

post in WWW::Mechanize

$bot->post($url, [sid => 'id', email => '[email protected]']); 
+0

它說內部服務器error.Have編輯與最新代碼的問題。我刪除了cookie的長度和id,因爲我不知道如何用值替換cookie。另外sid的價值應該是什麼。我從哪裏得到它在程序中 – user1092042

+0

你寫了'v2 @ d.com',但應該是'v @ d.com'。 – daxim

+0

只是另一封電子郵件。電子郵件實際上是一個輸入字段。任何使用@和.com的東西都被接受。另外,我將如何從程序中動態獲取ID - 在發佈數據中,我用ID簡單替換了我的ID號。實際上它是一個實際的數字。 – user1092042