作为我论文论文的一部分,我构建了一个“机器人”,用于抓取C语言程序的官方论坛,并搜索常见问题以发布回复。我必须模拟登录才能发布相应的回复。登录形式如下:使用Java登录到vbulletin论坛
- 登录表单 - 形式的行动= “?login.php中做=登录” 方法= “邮报” 的onsubmit = “md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf,0)” > script type =“text/javascript”src =“clientscript/vbulletin_md5.js?v = 385”> table cellpadding =“0”cellspacing =“3”border =“0”> tr> td class =“ smallfont”样式= “空白:NOWRAP;”>Όνομαχρήστη TD>
TD类= “smallfont” NOWRAP = “NOWRAP”>ΑυτόματηΣύνδεση /TR> TR> TD类= “smallfont”>Κωδικός TD> TD> /TR> /TABLE>
INPUT TYPE = “隐藏” 名称= “S” 值= “”/> INPUT TYPE = “隐藏”名称=“securitytoken”value =“guest”/> input type =“hidden”name =“do”value =“login”/> input type =“hidden”name =“vb_login_md5password”/> input type =隐藏”的名字=‘vb_login_md5password_utf’/> /FORM> ! - /登录窗体 - >
我已经明白,我需要MD5哈希密码,但我不能任何登录。我使用POST方法,我准备内容执行以下操作:
content = "do=login&url=login.php" + "&vb_login_md5password=" + md5_pass+ "&vb_login_md5password_utf="+ md5_pass + "&s=&securitytoken=guest&vb_login_username=" + UserName + "&vb_login_password=" + PassWprd;
我再发做以下的角逐:
urlConnection = (HttpURLConnection)(new URL(targetUrl).openConnection());
// Specifying that we intend to use this connection for input
urlConnection.setDoInput(true);
// Specifying that we intend to use this connection for output
urlConnection.setDoOutput(true);
// Specifying the method of HTTP request which is POST
// throws ProtocolException
urlConnection.setRequestMethod("POST");
// Specifying the content type of our post
urlConnection.setRequestProperty("Content-Type", POST_CONTENT_TYPE);
urlConnection.setRequestProperty("Content-length",String.valueOf (content.length()));
// urlConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");
// Prepare an output stream for writing data to the HTTP connection
// throws IOException
dataOutputStream = new DataOutputStream(urlConnection.getOutputStream());
dataOutputStream.writeBytes(content);
尽管如此,我无法登录。我相信我发送的表单有问题,但我找不到。任何帮助将不胜感激,因为我必须在几天内完成该计划。
我做了你所说的,我找到了正确的表单和正确的POST登录链接,最后它工作。感谢您的帮助:P – fysob 2010-07-13 16:15:23
@fysob您可以使用您的代码发布答案吗?我试图在vbulletin论坛上完成同样的事情。 – localhost 2014-11-25 05:12:48