日期:2014-05-17 浏览次数:20626 次
HttpClient client = new HttpClient();
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
PostMethod post = new PostMethod("http://www.renren.com/PLogin.do");
NameValuePair username = new NameValuePair("email", "xxxxx@163.com");
NameValuePair password = new NameValuePair("password", "xxxxxxx");
post.setRequestHeader("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10");
post.setRequestBody(new NameValuePair[] { username, password });
client.executeMethod(post);
int status = client.executeMethod(post);
System.out.println(status);
byte[] b = post.getResponseBody();
System.out.println(new String(b,"UTF-8"));
if (status == 301 || status == 302) {
Header locationHeader = post.getResponseHeader("location");
if(locationHeader != null){
String url = locationHeader.getValue(); // 得到跳转href
GetMethod g = new GetMethod(url);
client.executeMethod(g);
byte[] bs = g.getResponseBody();
System.out.println(new String(bs,"UTF-8"));
}
}
post.releaseConnection();
人家用伪静态了吧,
你的地址去不了