1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > java新浪模拟登录 HttpClient模拟登录新浪微博!

java新浪模拟登录 HttpClient模拟登录新浪微博!

时间:2019-05-10 08:40:00

相关推荐

java新浪模拟登录 HttpClient模拟登录新浪微博!

当前位置:我的异常网» Java Web开发»HttpClient模拟登录新浪微博!

HttpClient模拟登录新浪微博!

网友分享于:-12-16浏览:2099次

HttpClient模拟登录新浪微博求助!!!!!!!!!!

以下是参考网上找到的代码修改后的源码,可是登录不成功,望指教或探讨!!!

QQ:940154985

packagecn.vangdo.search;

importjava.io.BufferedReader;

importjava.io.File;

importjava.io.FileOutputStream;

importjava.io.IOException;

importjava.io.InputStreamReader;

importjava.util.ArrayList;

importjava.util.List;

importjava.util.regex.Matcher;

importjava.util.regex.Pattern;

mons.io.IOUtils;

importorg.apache.http.HttpEntity;

importorg.apache.http.HttpResponse;

importorg.apache.http.NameValuePair;

importorg.apache.http.client.HttpClient;

importorg.apache.http.client.entity.UrlEncodedFormEntity;

importorg.apache.http.client.methods.HttpGet;

importorg.apache.http.client.methods.HttpPost;

importorg.apache.http.impl.client.DefaultHttpClient;

importorg.apache.http.message.BasicNameValuePair;

publicclassSinaLogin{

privatefinalstaticHttpClientclient=newDefaultHttpClient();

/**

*抓取网页

*

*@paramurl

*@throwsIOException

*/

staticStringget(Stringurl)throwsIOException{

HttpGetget=newHttpGet(url);

HttpResponseresponse=client.execute(get);

System.out.println(response.getStatusLine());

HttpEntityentity=response.getEntity();

Stringresult=dump(entity);

get.abort();

returnresult;

}

/**

*执行登录过程

*

*@paramuser

*@parampwd

*@paramdebug

*@throwsIOException

*/

staticvoidlogin(Stringuser,Stringpwd)throwsIOException{

HttpPostpost=newHttpPost(

"/sso/login.php?client=ssologin.js(v1.3.17)");

post.setHeader("User-Agent",

"Mozilla/5.0(X11;Linuxi686;rv:5.0)Gecko/0101Firefox/5.0");

post.setHeader("Referer","/");

post.setHeader("Content-Type","application/x-www-form-urlencoded");//登录表单的信息

Listqparams=newArrayList();

qparams.add(newBasicNameValuePair("entry","account"));

qparams.add(newBasicNameValuePair("gateway","1"));

qparams.add(newBasicNameValuePair("from",""));

qparams.add(newBasicNameValuePair("savestate","0"));

qparams.add(newBasicNameValuePair("useticket","0"));

qparams.add(newBasicNameValuePair("ssosimplelogin","1"));

qparams.add(newBasicNameValuePair("service","account"));

qparams.add(newBasicNameValuePair("servertime","1323790225"));

qparams.add(newBasicNameValuePair("nonce","FUD0TL"));

//servertime=1309164392

//nonce=PJZCHM

qparams.add(newBasicNameValuePair("pwencode","wsse"));

qparams.add(newBasicNameValuePair("encoding","UTF-8"));

qparams.add(newBasicNameValuePair(

"url",

"/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack"));

qparams.add(newBasicNameValuePair("returntype","IFRAME"));

qparams.add(newBasicNameValuePair("setdomain","1"));

qparams.add(newBasicNameValuePair("username",user));

qparams.add(newBasicNameValuePair("password",pwd));

文章评论

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。