- 论坛徽章:
- 0
|
本帖最后由 lanparky 于 2010-09-05 22:27 编辑
这是由于提交时HTML::Form自动编码的问题,如果没有指定编码格式,默认是utf-8,如果指定了gbk,接收的地址必须有对应的解码程序才可以正常显示中文.所以修改下模块HTML::Form (先把文件的只读取消),在HTML::Form里找到- eval { require Encode };
- $Encode_available = !$@;
复制代码 在后面加上把HTML:Form自动编码的功能关闭.提交程序代码改为
- use WWW::Mechanize;
- use Encode;
- use LWP::ConnCache;
- $url="http://bbs.sh.libaclub.com/message.php?action=write";
- my $mech=WWW::Mechanize->new();
- $mech->conn_cache(LWP::ConnCache->new);
- $mech->agent_alias('Windows IE 6');
- $mech->add_header(Referer=>' http://bbs.sh.libaclub.com/message.php');
- $mech->add_header("Accept-Charset" =>'GBK;q=0.7,*;q=0.7');
- $mech->add_header("Accept-Language"=>'zh-cn;q=0.5');
- $mech->add_header(Cookie=>'sessionhash=fa55180844a4152e93b64fc17482b53f; __utma=87665927.1972509085.1283527516.1283616492.1283653233.7; __utmz=87665927.1283527516.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=87665927; mytopictabs=0; navtoptabs=0; PHPSESSID=1c4aafe2bad88da7cb26b89cd514dd42; __utmb=87665927.6.10.1283653233');
- $mech->get($url);
- my $res = $mech->res;
- ##关闭decoded_content会自动解码,把返回的内容按页面原样输出
- $html= $res->decoded_content(charset => 'none');
- $mech->update_html( $html );
- $form=$mech->form_name("form1");
- $mech->field("receiverName","sx98083714");
- my $subject="测试题目";
- $mech->field("topic",$subject);
- my $content="明月几时有,把酒问清天,不知天上宫阙,今夕是何年!";
- $mech->field("content",$content);
- $mech->submit();
- $res = $mech->res;
- $html= $res->decoded_content(charset => 'none');
- $mech->update_html( $html );
- print $mech->dump_all();
复制代码 |
|