只有http头通信? – 请解释

下面的屏幕截图使用萤火虫。 点击loginbutton后,捕获的firefox < – > web服务器通信发生。 但我无法看到我的Firefox中的任何redirect。 这是否意味着firefox和web服务器只在http头级别上进行通信?

我已经准备好ruby/机械化脚本来从论坛上刮掉一些细节。 我使用vBulletin.org论坛对其进行了testing/编码。 然后,我设法login到我的testing论坛,并愉快地移动到最终我的脚本使用正确的论坛。 但我无法login。我的脚本只返回login页面,我认为是“不成功的login尝试”。

通信截图http://i49.tinypic.com/13zcqj6.jpg

login页面的html

 <form class="login" method="post"> <fieldset> <legend>Members Login</legend> <div> <label for="auth_username">Username</label> <input id="auth_username" name="auth_username"> </div> <div> <label for="auth_password">Password</label> <input id="auth_password" name="auth_password" type="password"> </div> </fieldset> <div class="buttons"> <input name="auth_login" type="submit" value="Login"><p class="note"><a href="/forgotpassword">Forgot your password?</a></p> </div> </form> 

我的ruby脚本

 require 'rubygems' require 'mechanize' #agent = WWW::Mechanize.new agent = WWW::Mechanize.new page = agent.get("http://www.vbulletin.org/forum/index.php") login_form = page.form_with(:action => 'login.php?do=login') puts login_form.fields.each { |f| puts "#{f.name} : #{f.value}" } login_form['vb_login_username'] = 'user name' login_form['vb_login_password'] = '' page = agent.submit login_form output = File.open("login.html", "w") {|f| f.write(page.parser.to_html) } 

从没有工作的login尝试机械化日志

  INFO -- : Net::HTTP::Get: /login?auth_successurl=http://www.somedomain.com/forum/yota?baz_r=1 DEBUG -- : request-header: accept-language => en-us,en;q=0.5 DEBUG -- : request-header: connection => keep-alive DEBUG -- : request-header: accept => */* DEBUG -- : request-header: accept-encoding => gzip,identity DEBUG -- : request-header: user-agent => WWW-Mechanize/0.9.3 (http://rubyforge.org/projects/mechanize/) DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7 DEBUG -- : request-header: host => www.somedomain.com DEBUG -- : request-header: keep-alive => 300 DEBUG -- : Read 400 bytes DEBUG -- : Read 1424 bytes DEBUG -- : Read 2448 bytes DEBUG -- : Read 3211 bytes DEBUG -- : response-header: vary => Accept-Encoding DEBUG -- : response-header: cache-control => no-store, no-cache, must-revalidate, post-check=0, pre-check=0 DEBUG -- : response-header: connection => close DEBUG -- : response-header: expires => Thu, 19 Nov 1981 08:52:00 GMT DEBUG -- : response-header: content-type => text/html; charset=utf-8 DEBUG -- : response-header: date => Fri, 29 Jan 2010 23:43:12 GMT DEBUG -- : response-header: content-encoding => gzip DEBUG -- : response-header: server => Apache/2.2.3 (CentOS) DEBUG -- : response-header: content-length => 3211 DEBUG -- : response-header: set-cookie => PHPSESSID=7cfilg86ju2ldcgso22246hpu4; path=/, WebStats:visitorId=lSMkcwuSWEE%3D; expires=Mon, 27-Jan-2020 23:43:12 GMT; path=/, WebStats:sessionId=%2B2HHK296t%2BQ%3D; expires=Mon, 27-Jan-2020 23:43:12 GMT; path=/ DEBUG -- : response-header: accept-ranges => bytes DEBUG -- : response-header: pragma => no-cache DEBUG -- : gunzip body DEBUG -- : saved cookie: PHPSESSID=7cfilg86ju2ldcgso22246hpu4 DEBUG -- : saved cookie: WebStats:visitorId=lSMkcwuSWEE%3D DEBUG -- : saved cookie: WebStats:sessionId=%2B2HHK296t%2BQ%3D INFO -- : status: 200 DEBUG -- : query: "auth_username=radek&auth_password=mypassword" INFO -- : Net::HTTP::Post: /login?auth_successurl=http://www.somedomain.com/forum/yota?baz_r=1 DEBUG -- : request-header: accept-language => en-us,en;q=0.5 DEBUG -- : request-header: connection => keep-alive DEBUG -- : request-header: accept => */* DEBUG -- : request-header: accept-encoding => gzip,identity DEBUG -- : request-header: content-type => application/x-www-form-urlencoded DEBUG -- : request-header: user-agent => WWW-Mechanize/0.9.3 (http://rubyforge.org/projects/mechanize/) DEBUG -- : request-header: cookie => WebStats:sessionId=%2B2HHK296t%2BQ%3D; WebStats:visitorId=lSMkcwuSWEE%3D; PHPSESSID=7cfilg86ju2ldcgso22246hpu4 DEBUG -- : request-header: referer => http://www.somedomain.com/login?auth_successurl=http://www.somedomain.com/forum/yota?baz_r=1 DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7 DEBUG -- : request-header: content-length => 43 DEBUG -- : request-header: host => www.somedomain.com DEBUG -- : request-header: keep-alive => 300 DEBUG -- : Read 650 bytes DEBUG -- : Read 1674 bytes DEBUG -- : Read 2698 bytes DEBUG -- : Read 3211 bytes DEBUG -- : response-header: vary => Accept-Encoding DEBUG -- : response-header: cache-control => no-store, no-cache, must-revalidate, post-check=0, pre-check=0 DEBUG -- : response-header: connection => close DEBUG -- : response-header: expires => Thu, 19 Nov 1981 08:52:00 GMT DEBUG -- : response-header: content-type => text/html; charset=utf-8 DEBUG -- : response-header: date => Fri, 29 Jan 2010 23:43:13 GMT DEBUG -- : response-header: content-encoding => gzip DEBUG -- : response-header: server => Apache/2.2.3 (CentOS) DEBUG -- : response-header: content-length => 3211 DEBUG -- : response-header: accept-ranges => bytes DEBUG -- : response-header: pragma => no-cache DEBUG -- : gunzip body INFO -- : status: 200 

redirect通常通过HTTP响应状态码301(永久移动)或302(find/移动临时)来实现。 用于执行redirect的301和302 HTTP响应状态代码包含在HTTP标头中。

仅仅因为你没有“在Firefox中看到任何redirect”并不意味着redirect没有发生:在幕后。

还有另外一种方法来redirect,在页面中使用JavaScript。 使用JavaScript,redirect对用户来说是显而易见的,他们可以先显示一个页面,然后redirect到其他位置。 但是,那些不是HTTPredirect的HTTP头响应状态代码。

为了解决你关于Ruby的问题:你应该问Stack Overflow的问题。 但是,简而言之,是的,您应该能够使用任何服务器端Web技术设置301和302redirect响应代码。


更新:在下面的评论中解决进一步的问题:

如果您想了解更多关于HTTP如何工作的信息 ,那么我推荐以下书籍: HTTP:David Gourley&Brian Totty的权威指南 。 您也可以参考RFC 2616定义的官方HTTP标准:超文本传输​​协议 – HTTP / 1.1 。

至于为什么在你的问题上面的一系列请求需要11个步骤 ,你将需要问有关软件的原始作者。 它可能可以用更less的步骤来实施,但可能不仅仅是一步。 考虑一下,服务器需要至less有一个redirect在用户的浏览器中设置一个cookie,然后再发送给受保护的资源。

由于您正在尝试复制基于Cookie的自定义身份validation机制,因此我还build议您将研究重点放在如何构build此类系统。

如果您正在尝试编写login页面,则应该确保程序POST到服务器的内容与各方面的真实请求相匹配,包括您当前未包含的参数。

此外,您需要确保您的代码正在接受并发送服务器发送的任何Cookie。 不保存由服务器发送的cookies是这种练习的常见错误。 此外,您需要指示您正在使用的HTTP通信库来跟踪redirect。 其中一些默认不遵循redirect。

最后 – debugging,捕获请求和响应标题和正文,从网页,从您的程序, 并比较它们 。 怀疑有任何分歧。