首页 新闻 会员 周边

HttpClient 访 问启用认证的页面

0
悬赏园豆:20 [已解决问题] 解决于 2015-09-28 16:01

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;


public class BlogTestHttpClient {

public BlogTestHttpClient() {
}

/**
* @param args
* @throws IOException
* @throws HttpException
*/
public static void main(String[] args) throws HttpException, IOException {
HttpClient client = new HttpClient();
client.getState().setCredentials(
"www.cnblogs.com",
"user/signin",
new UsernamePasswordCredentials("username", "password")
);
GetMethod get = new GetMethod("http://home.cnblogs.com/u/Sir-Lin/followers/1/");
get.setDoAuthentication( true );
int status = client.executeMethod( get );
System.out.println(status+"\n"+ get.getResponseBodyAsString());
get.releaseConnection();
}

}

为什么一直报错

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:101)

除了这种方式还有没有其他的实现思路

戴杭林的主页 戴杭林 | 初学一级 | 园豆:170
提问于:2015-09-25 14:42
< >
分享
最佳答案
0

自己解决了 原来是没有org/apache/commons/logging这个包 一直误以为导了commons/httpclient这个包就够了

戴杭林 | 初学一级 |园豆:170 | 2015-09-25 15:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册