在 WWW::Mechanize 中使用“get”直接访问 URL 时如何保持身份验证?
我是 WWW::Mechanize 的新手,但我知道如何登录以及如何使用follow_link
方法在我登录时访问其他页面。但是当我想直接访问不在页面上的链接时,我会失去身份验证。
问题的快速示例:
my $LoginURL = "http://www.website.com/user/login.jsp?";
my $DirectURL= "/Somefile?param1¶m2";
$mech = WWW::Mechanize->new();
$mech->get($LoginURL);
$mech->submit_form( ... ); # fields and stuff, works fine.
$mech->get($DirectURL); # This part fails and I'm using the direct URL.
我了解如何登录,并且可以使用 follow_link
方法进行导航,但是当我想使用 get
访问不在页面上的 URL 时code> 方法我只是失去了我的身份验证。
当我想要访问不在当前页面上的直接 URL 时,我必须做什么才能保持身份验证?
I'm new to WWW::Mechanize but I know how to login and then how to use the follow_link
method to access other pages while I'm logged in. But when I want to access a link directly that is not on the page, I lose my authentication.
Quick sample of the problem:
my $LoginURL = "http://www.website.com/user/login.jsp?";
my $DirectURL= "/Somefile?param1¶m2";
$mech = WWW::Mechanize->new();
$mech->get($LoginURL);
$mech->submit_form( ... ); # fields and stuff, works fine.
$mech->get($DirectURL); # This part fails and I'm using the direct URL.
I understand how to login and I can navigate around with the follow_link
method, but when I want to access a URL that is not on the page using the get
method I simply lose my authentication.
What will I have to do in order to remain authenticated when I want to access a direct URL not located on the current page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 HTTP 是一种无状态协议,因此每个请求都独立于前一个请求。在 HTTP 1.1 之前的版本中,HTTP 事务的默认行为是客户端联系服务器、发送请求并接收响应,然后客户端和服务器都断开 TCP 连接。如果客户端需要服务器上的另一个资源,则必须重新建立另一个 TCP 连接,请求资源,然后断开连接。如果您已成功通过身份验证,当您尝试访问下一页时,目标网站可能会“忘记”这一点。尝试查看 HTTP“连接”标头中包含哪个值。它应该是“keep-alive”而不是“TE,close”。如果这是问题,请尝试修改“连接”标头。你可以尝试这样的事情:
希望它有帮助。
Since HTTP is a stateless protocol, each request is independent of the previous one. In versions previous to HTTP 1.1, the default behavior for HTTP transactions is for a client to contact a server, send a request, and receive a response, and then both the client and server disconnect the TCP connection. If the client needs another resource on the server, it has to reestablish another TCP connection, request the resource, and disconnect. If you have successfully authenticated, the target website might "forget" that when you trying to access the next page. Try to see which value is included in the HTTP "Connection" header. It should be "keep-alive" and not "TE, close". If this is the issue try to modify the "Connection" header. You can try something like this:
Hope it helps.
$mech->get() 是 LWP::UserAgent 的重载。它需要绝对 URL。
$mech->get() is an overload of LWP::UserAgent. It expects absolute URLs.