项目中不一定用到,可以用自带的和httpmine代替
在这个jar包中一有一些重要的方法,其中包括封装http的请求的功能,本文可以做一个参考;
- 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);
- }
- }
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);
}
}
前提是要加入一些jar包才能正常运行的,jar包如下