加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何使用Perl的LWP :: Simple发送cookie?

发布时间:2020-12-16 06:22:08 所属栏目:大数据 来源:网络整理
导读:use LWP::Simple;use HTML::LinkExtor;use Data::Dumper;#my $url = shift @ARGV;my $content = get('example.com?GET=whateverIwant');my $parser = HTML::LinkExtor-new(); #create LinkExtor object with no callbacks$parser-parse($content); #parse co
use LWP::Simple;
use HTML::LinkExtor;
use Data::Dumper;
#my $url = shift @ARGV;
my $content = get('example.com?GET=whateverIwant');
my $parser = HTML::LinkExtor->new(); #create LinkExtor object with no callbacks
$parser->parse($content); #parse content

现在,如果我想发送POST和COOKIE信息以及HTTP标头,我如何使用get funciton配置它?或者我必须自定义我自己的方法?

我的主要兴趣是Cookies!发帖!

解决方法

LWP::Simple用于非常简单的HTTP GET请求.如果你需要做更复杂的事情(比如cookie),你必须升级到完整的 LWP::UserAgent. cookie_jar是一个 HTTP::Cookies对象,你可以使用它的set_cookie方法添加一个cookie.

use LWP::UserAgent;

my $ua = LWP::UserAgent->new(cookie_jar => {}); # create an empty cookie jar

$ua->cookie_jar->set_cookie(...);

my $rsp = $ua->get('example.com?GET=whateverIwant');
die $rsp->status_line unless $rsp->is_success;
my $content = $rsp->decoded_content;
...

LWP :: UserAgent也有一个post方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读