黑马程序员技术交流社区
标题:
httpclient写的模拟人人网登陆
[打印本页]
作者:
long362144768
时间:
2013-9-25 22:17
标题:
httpclient写的模拟人人网登陆
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class httpclientpost {
public static void main(String[] args) {
HttpClient httpclientpost = new HttpClient();
String url = "http://www.renren.com/PLogin.do";
PostMethod postmethod = new PostMethod(url);
NameValuePair[] data = {new NameValuePair("email", "XXXXXX"),
new NameValuePair("password", "******")};//"X"和“*”部分是人人网对应的账号和密码
postmethod.setRequestBody(data);
int statusCode;
try {
statusCode = httpclientpost.executeMethod(postmethod);
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY ||
statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
Header locationHeader = postmethod.getResponseHeader("location");
String location = null;
if (locationHeader != null) {
location = locationHeader.getValue();
System.out.println("The page was redirected to:" + location);
}else {
System.err.println("Location field value is null.");
}
return;
}
else{
byte[] responsebody = postmethod.getResponseBody();
System.out.println(new String(responsebody));
}
} catch (HttpException e) {
// TODO Auto-generated catch block
System.out.println("Please check your provided http address!");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
postmethod.releaseConnection();
}
}
}
1,可以改进成网页爬虫,抓取别人的url,自动访问别人的主页。
2,也是网络抢票软件的原理哦,
问题:无法实现自动注册,需要破解验证码,谁有验证码的代码呢?
作者:
aspoMAN
时间:
2013-9-28 22:23
lz问一下,大部分的服务器都可以判断出来你是机器登陆还是人登陆的,怎么绕开它的判断呢? 那些参数该怎么获取呢?
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2