package com.hyl.main;
import java.io.IOException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class Login {
/**
* @param args
*/
public static void main(String[] args) {
String loginUrl="http://hylbbs.yupage.com/login.php?action=login";
HttpClient httpclient=new HttpClient();
PostMethod post=new PostMethod(loginUrl);
post.addParameter("username","xxxx");
post.addParameter("userpass","xxxx");
try {
int statuscode=httpclient.executeMethod(post);
//Header[] headers=post.getRequestHeaders();
System.out.println(statuscode);
if(statuscode==200){
System.out.println("登录成功");
GetMethod redirect = new GetMethod("http://hylbbs.yupage.com/index.php");
httpclient.executeMethod(redirect);
Header[] headers=redirect.getRequestHeaders();
//System.out.println(cookie);
String str="";
for(int i=0;i<headers.length;i++){
Header header=headers[i];
str+=header.toString()+";";
}
System.out.println(str);
System.out.println(redirect.getResponseBodyAsString());
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
移动互联网技术论坛 访问地址:http://hylbbs.yupage.com