免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2473 | 回复: 5

AnyEvent::http如何才能接受cookie? [复制链接]

论坛徽章:
0
发表于 2012-07-23 17:58 |显示全部楼层
AnyEvent::http如何才能接受cookie?小弟http不太熟悉,哪位帮一下?

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2012-07-23 22:40 |显示全部楼层
  1. cookie_jar => $hash_ref
  2. Passing this parameter enables (simplified) cookie-processing, loosely based on the original netscape specification.

  3. The $hash_ref must be an (initially empty) hash reference which will get updated automatically. It is possible to save the cookie jar to persistent storage with something like JSON or Storable - see the AnyEvent::HTTP::cookie_jar_expire function if you wish to remove expired or session-only cookies, and also for documentation on the format of the cookie jar.

  4. Note that this cookie implementation is not meant to be complete. If you want complete cookie management you have to do that on your own. cookie_jar is meant as a quick fix to get most cookie-using sites working. Cookies are a privacy disaster, do not use them unless required to.

  5. When cookie processing is enabled, the Cookie: and Set-Cookie: headers will be set and handled by this module, otherwise they will be left untouched.
复制代码
http://search.cpan.org/~mlehmann/AnyEvent-HTTP-2.14/HTTP.pm

论坛徽章:
0
发表于 2012-07-24 09:33 |显示全部楼层
回复 2# py


    py兄,这个小弟已经看过,还是不懂,能否给个例子?谢谢。

论坛徽章:
0
发表于 2012-07-24 10:01 |显示全部楼层
  1. #!/bin/env perl

  2. use strict;
  3. use warnings;
  4. use AnyEvent;
  5. use AnyEvent::HTTP;
  6. use Data::Dumper;

  7. my $url = "http://www.baidu.com";
  8. my $cookie_jar = {};


  9. my $cv = AnyEvent->condvar;

  10. $cv->begin();
  11. http_get($url,
  12.     cookie_jar => $cookie_jar,
  13.     sub {
  14.         my ($content, $hdr) = @_;

  15.         print $hdr->{Status}, "\n";
  16.         print Dumper($cookie_jar), "\n";

  17.         $cv->end();
  18.     });

  19. $cv->recv();
复制代码

论坛徽章:
0
发表于 2012-07-24 10:18 |显示全部楼层
本帖最后由 wendaozhe 于 2012-07-24 10:41 编辑

回复 4# 3P主义


   自己弄错了,谢谢两位!

论坛徽章:
0
发表于 2012-07-24 12:53 |显示全部楼层
抓包的结果使用AnyEvent::http 访问和直接使用浏览器访问还是有区别的,AnyEvent::http中的headers中的cookie和set-cookie如何设置?今天调了设置,可是还是不能跟浏览器访问的一样。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP