所以我试图从这个服务器成功登录:www.liuserver.com 和我使用两个类 LoginLayout.java 和 CustomHttpclient.java,现在我已经使用 Httpwatch 监视浏览器与服务器的通信以跟踪类型回复服务器生成的帖子(生成包含用户提供的用户名和密码的 url 以及自动生成的 x 和 y 整数,在此示例中为 31 和 1,其他时候嘿只是零)发布到网页看起来像这样 :
POST /login.php HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Referer: https://www.liuserver.com/login.php
Accept-Language: en-US
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: www.liuserver.com
Content-Length: 38
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: PHPSESSID=e3q4d78jkci3shhn8fq1tlf7i5
USER=20730312&PASS=Password44&x=32&y=1
现在我已成功生成带有参数的 url,我将它们发布到服务器,但当然它给了我否定的答复,现在我被告知,在 httpwatch 插件的 cookie 选项卡中很明显我需要发送phpsessionid 作为 cookie,我的问题是如何做到这一点,我应该在哪个类中放置用于发送带有参数的 cookie 的代码,以及如何在成功验证后跟踪服务器的回复类型的用户名和密码。回复流看起来像:
HTTP/1.1 302 Found
Server: nginx/1.0.14
Date: Tue, 01 May 2012 15:57:06 GMT
Content-Type: text/html
Connection: keep-alive
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: student/
X-Powered-By: PleskLin
Content-Length: 0
登录页面的完整网址:https://www.liuserver.com/login.php
更新 :
好的,我已成功从服务器获取 phpsessionid cookie,我可以查看它的值,现在我必须使用将我的登录参数提交到 erver
response = CustomHttpClient.executeHttpPost("https://www.liuserver.com/login.php", postParameters);
但是我应该在哪里放置包含 phpsession id 的 cookie 在这个方法中执行 httpPost 我可以更改方法的参数并将 cookie 传递到那里吗?