如何用Java实现模拟登录Discuz!论坛并下载返回的html代码?

如何用Java实现模拟登录Discuz!论坛并下载返回的html代码?,第1张

package orgshaw;

import orgapachecommonshttpclientCookie;

import orgapachecommonshttpclientHttpClient;

import orgapachecommonshttpclientNameValuePair;

import orgapachecommonshttpclientmethodsGetMethod;

import orgapachecommonshttpclientmethodsPostMethod;

public class BaiyouBBS {

static final String LOGON_SITE = "wwwqiluyiyoucom";

static final int LOGON_PORT = 80;

public Cookie[] login(String name, String pas) {

try {

HttpClient client = new HttpClient();

clientgetHostConfiguration()setHost(LOGON_SITE, LOGON_PORT);

PostMethod post = new PostMethod("/loggingphpaction=login");

clientexecuteMethod(post);

String responseString = new String(postgetResponseBody(), "gbk");

postreleaseConnection();

String formhash = getFormHash(responseString);

Systemoutprintln(formhash);

post = new PostMethod("/loggingphpaction=login&");

NameValuePair[] params = new NameValuePair[11];

params[0] = new NameValuePair("loginfield", "username");

params[1] = new NameValuePair("username", name);

params[2] = new NameValuePair("password", pas);

params[3] = new NameValuePair("referer", "indexphp");

params[4] = new NameValuePair("questionid", "0");

params[5] = new NameValuePair("answer", "");

params[6] = new NameValuePair("cookietime", "2592000");

params[7] = new NameValuePair("formhash", formhash);

params[8] = new NameValuePair("loginmode", "");

params[9] = new NameValuePair("loginsubmit", "true");

params[10] = new NameValuePair("styleid", "");

postsetRequestBody(params);

clientexecuteMethod(post);

// responseString = new String(postgetResponseBody(), "gbk");

postreleaseConnection();

GetMethod get = new GetMethod("/indexphp");

clientexecuteMethod(get);

responseString = new String(getgetResponseBody(), "gbk");

getreleaseConnection();

Systemoutprintln(responseString);

} catch (Exception e) {

eprintStackTrace();

}

return null;

}

public String getFormHash(String htmlContent) {

try {

int start = htmlContentindexOf("name=\"formhash\"");

start = htmlContentindexOf("value=\"", start) + 7;

int end = htmlContentindexOf("\"", start);

String formhash = htmlContentsubstring(start, end);

return formhash;

} catch (RuntimeException e) {

throw e;

}

}

public static void main(String[] args) {

new BaiyouBBS()login("zzzxxxzzz", "zzzxxxzzz");

}

}

这个一般是网络问题导致的,建议关闭验证码可以用安全问答来验证,设置一些比较有特色的问题,比如圆明园在哪个城市?答案设置为北京,这种灌水机是无法识别的。也可以用云验证码插件试试,希望DZ动力能够帮到你。

Discuz论坛无法显示验证码可能与主机环境有关或者与程序版本选择有关

在无法判断到底是什么原因的情况下

请登录网站地址/adminphp

用管理员登录信息登录,这里不需要验证码

登录后在防灌水设置中将验证码选择为验证码

或者在验证设置页将登录验证码关闭

DZ动力希望可以帮到您

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » 如何用Java实现模拟登录Discuz!论坛并下载返回的html代码?

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情