2013-10-22 36 views
-2

Perl的機械化表單字段我想提交使用沒有名字

my $fields = { 
'f1' => 'type_contract', 
'f2' => '0', 
. 
. 
. 
}; 
$mech->submit_form(with_fields => $fields); 

該問題的形式是,一些表單字段要麼沒有重名的名字。我如何使用,而不是「名稱」,「ID」來設定表單字段的數據?

謝謝。

回答

-1

我首先正確地形成頭部解決它。請閱讀HTTP::Headers

my $cont_h = HTTP::Headers->new(
'Host' => 'http:// [the url]', 
'User-Agent' =>  'Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130307 Firefox/17.0', 
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 
. 
. 
. 
. 
); 

我做的錯誤是將Post數據作爲散列傳遞。發佈數據是字節串,在這種情況下也是內容。

my $cont_post_data = 'chargingContractHistoryCsvDto.searchType=type_contract& chargingContractHistoryCsvDto.searchItem=0&chargingContractHistoryCsvDto.searchDateFrom='.$start_t.'&chargingContractHistoryCsvDto.searchDateTo='.$end_t.'&'; 

形成HTTP請求。請閱讀HTTP::Request

my $cont_req = HTTP::Request->new('POST', $URI, $cont_h, $cont_post_data); 

並用perl mechanize發送請求。

my $cont_response = $mech->request($cont_req);