-2

我正在尝试使用

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

问题是表单中的某些字段要么没有重复名称的名称。如何使用“id”而不是“name”在表单字段上设置数据?

谢谢你。

4

1 回答 1

-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);
于 2013-10-24T04:29:02.183 回答