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)
除了这种方式还有没有其他的实现思路
自己解决了 原来是没有org/apache/commons/logging这个包 一直误以为导了commons/httpclient这个包就够了