【发布时间】:2010-03-19 06:22:19
【问题描述】:
我是 Perl 新手,我想编写一个 Perl 程序:
- 创建一个 HTTP 请求
- 将其发送到任何 URL(例如 http://www.google.com)
- 在请求中包含一个 cookie
- 在文件中记录 http 响应代码
我试过这个:
#!/usr/bin/perl
require HTTP::Request;
require LWP::UserAgent;
$request = HTTP::Request->new(GET => 'http://www.google.com/');
$ua = LWP::UserAgent->new;
$ua->cookie_jar({file => "testcookies.txt",autosave =>1});
$response = $ua->request($request);
if($response->is_success){
print "sucess\n";
print $response->code;
}
else {
print "fail\n";
die $response->code;
}
请告诉如何在“请求”中设置cookie,即
当我们发送 HTTP::Request 时如何设置 cookie
我期待的是这样的:
$request = HTTP::Request->new(GET => 'http://www.google.com/');
$ua = LWP::UserAgent->new;
$ua->new CGI::Cookie(-name=>"myCookie",-value=>"fghij");
这可能吗??
【问题讨论】:
-
你自己试过吗?你被什么困住了?我也不确定腻子/技巧与您的问题有何关系。
-
Cookies 存储在客户端。也许您想发送 cookie 值而不是 cookie 本身。
-
+1
pls tell how to set cookie in 'request'是我以前从未见过的错误消息——甚至在 Perl 中也没有 :) -
@Jørn Schou-Rode:哎呀!忘记添加“错误消息”他们的..无论如何都解决了问题已编辑。
标签: perl