主 题: 求助,apache.commons.?
我想登陆我的论坛,用程序采集论坛信息,研究了几天,怎么也登陆不了,请高手指点了,谢谢!
以下是我的代码:
package com.getemail;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.NameValuePair;
public class BbsUp {
public static void main(String[] args) {
HttpClient httpClient = new HttpClient();
String loginUrl = "http://bbs.shanbeiren.com/logging.php?action=login";//登陆url
try{
//登陆
PostMethod postMethod=new PostMethod(loginUrl);
//登陆页面表单
NameValuePair formhash = new NameValuePair("formhash", "6a49b97f");
NameValuePair referer = new NameValuePair("referer",
"/viewpro.php?username=www");
NameValuePair loginmode = new NameValuePair("loginmode", "normal");
NameValuePair styleid = new NameValuePair("styleid", "1");
NameValuePair cookietime = new NameValuePair("cookietime", "2592000");
NameValuePair loginfield = new NameValuePair("loginfield", "username");
NameValuePair username = new NameValuePair("username", "www");
NameValuePair password = new NameValuePair("password", "40964096");
NameValuePair questionid = new NameValuePair("questionid", "0");
NameValuePair answer = new NameValuePair("answer", "");
postMethod.setRequestBody(new NameValuePair[] {loginmode,styleid,loginfield,username, password, formhash, referer,
cookietime,questionid,answer});
//打印返回状态
int statusCode=httpClient.executeMethod(postMethod);
System.out.println(statusCode);
//打印返回的信息
String response = null;
response = new String(postMethod.getResponseBodyAsString().getBytes("8859_1")); //打印结果页面
System.out.println(response);
postMethod.releaseConnection();
}catch(Exception err){
System.out.println(err.getMessage());
}
}
}
我想登陆我的论坛,用程序采集论坛信息,研究了几天,怎么也登陆不了,请高手指点了,谢谢!
以下是我的代码:
package com.getemail;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.NameValuePair;
public class BbsUp {
public static void main(String[] args) {
HttpClient httpClient = new HttpClient();
String loginUrl = "http://bbs.shanbeiren.com/logging.php?action=login";//登陆url
try{
//登陆
PostMethod postMethod=new PostMethod(loginUrl);
//登陆页面表单
NameValuePair formhash = new NameValuePair("formhash", "6a49b97f");
NameValuePair referer = new NameValuePair("referer",
"/viewpro.php?username=www");
NameValuePair loginmode = new NameValuePair("loginmode", "normal");
NameValuePair styleid = new NameValuePair("styleid", "1");
NameValuePair cookietime = new NameValuePair("cookietime", "2592000");
NameValuePair loginfield = new NameValuePair("loginfield", "username");
NameValuePair username = new NameValuePair("username", "www");
NameValuePair password = new NameValuePair("password", "40964096");
NameValuePair questionid = new NameValuePair("questionid", "0");
NameValuePair answer = new NameValuePair("answer", "");
postMethod.setRequestBody(new NameValuePair[] {loginmode,styleid,loginfield,username, password, formhash, referer,
cookietime,questionid,answer});
//打印返回状态
int statusCode=httpClient.executeMethod(postMethod);
System.out.println(statusCode);
//打印返回的信息
String response = null;
response = new String(postMethod.getResponseBodyAsString().getBytes("8859_1")); //打印结果页面
System.out.println(response);
postMethod.releaseConnection();
}catch(Exception err){
System.out.println(err.getMessage());
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货