在 Perl 中管理 cookie
我正在编写一个 Perl 脚本,它必须从服务器检索文件。服务器需要由不同服务器内部处理的身份验证。要检索该文件,我需要做的是首先 POST 到身份验证服务器,该服务器将返回两个 cookie。然后,我需要通过 GET 将这些 cookie 发送到包含我需要的文件的目标服务器。我正在网上寻找例子,甚至在这里寻找例子,但我仍然不清楚如何去做。有人可以向我展示如何执行此操作的示例吗?
I'm working on a Perl script that has to retrieve a file from a server. The server requires authentication that is handled internally by a different server. What I need to do to retrieve the file, is to first, POST to an authenticating server, which will return two cookies. I then need to send these cookies via a GET to the target server that has the file I need. I'm looking about the net and even here for examples, but I'm still unclear on how to go about this. Can someone show me an example of how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
制作一个实现 cookie 的
LWP::UserAgent
对象就像这样简单:请参阅此 文章 了解更多示例。
To make an
LWP::UserAgent
object that implements cookies is as simple as this:See this article for more examples.
您当然可以使用 Net::HTTP 并查看返回的标头来提取 cookie,然后在使用 write_request() 时将它们反馈回来,但这并不方便。
You can certainly use Net::HTTP and look at the returned headers to pull the cookies out, then feed them back when you use write_request(), but this is hardly convenient.