windows – 在Perl中发送HTTP请求
发布时间:2020-12-14 05:46:21 所属栏目:Windows 来源:网络整理
导读:如何在 Windows上的Perl中发送这样的请求? GET /index.html HTTP/1.1Host: www.example.orgCookie: test=quest 解决方法 您可以使用套接字执行此操作: use IO::Socket;my $sock = new IO::Socket::INET ( PeerAddr = 'www.example.org',PeerPort = '80',Pr
如何在
Windows上的Perl中发送这样的请求?
GET /index.html HTTP/1.1 Host: www.example.org Cookie: test=quest 解决方法
您可以使用套接字执行此操作:
use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => 'www.example.org',PeerPort => '80',Proto => 'tcp',); die "Could not create socket: $!n" unless $sock; print $sock "GET /index.html HTTP/1.0rn"; print $sock "Host: www.example.orgrn"; print $sock "Cookie: test=questrnrn"; print while <$sock>; close($sock); 但你可能想考虑使用LWP(libwww-perl)代替: use LWP::UserAgent; $ua = LWP::UserAgent->new; $req = HTTP::Request->new(GET => 'http://www.example.org/index.html'); $req->header('Cookie' => 'test=quest'); # send request $res = $ua->request($req); # check the outcome if ($res->is_success) { print $res->decoded_content } else { print "Error: " . $res->status_line . "n" } 您可以尝试阅读LWP cookbook以获取LWP简介. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 如何在X Windows上将进程窗口带到前台? (C )
- windows-phone-7 – 市场应用程序图标用法
- 如何排除一个属性在Azure Table存储中被持久化?
- windows-server-2008-r2 – Windows Server 2008
- windows10 安装python.msi出现error 2502/2503解
- 这个编辑器在Windows 10 cmd中由“git commit –
- 在Go中,如何自动将循环索引强制转换为uint?
- windows – 如何使用LaTeX编写路径?
- 如何查看响应端口号被个程序占用(Windows)
- active-directory – 创建多租户AD环境
热点阅读