commons-httpclient-3.1.jar的一些用处

2014-11-24 10:46:14 · 作者: · 浏览: 0

在这个jar包中一有一些重要的方法,其中包括封装http的请求的功能,本文可以做一个参考;

[java]
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;

public class TestLogin {

public static void main(String[] args) throws Exception, IOException {
TestLogin.testLogin();
}

public static void testLogin() throws HttpException, IOException{

HttpClient client = new HttpClient();
String url = "https://reg.163.com/logins.jsp";
PostMethod method = new PostMethod(url);
//method.addParameter("type", "1");
//method.addParameter("url", "");
//method.addParameter("product", "urs");
method.addParameter("username","xxxxxxx@126.com");
method.addParameter("password", "xxxxxx");
client.executeMethod(method);
String response = method.getResponseBodyAsString();
System.out.println(response);
}
}