700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > httpclient登录新浪微博手机版Weibo.cn

httpclient登录新浪微博手机版Weibo.cn

时间:2021-11-23 21:37:52

相关推荐

httpclient登录新浪微博手机版Weibo.cn

查看此页面的源代码

<form action="login_submit.php?rand=368437524&backURL=http%3A%2F%%2Fdpool%2Fttt%2Fhome.php%3Fs2w%3Dlogin&backTitle=%D0%C2%C0%CB%CE%A2%B2%A9&vt=4&revalid=2&ns=1" method="post"><div class="mg">手机号/电子邮箱/会员帐号:<br/><input type="text" name="mobile" size="30" value=""/><br/>密码:(<a href="login.php?backURL=http%3A%2F%%2Fdpool%2Fttt%2Fhome.php%3Fs2w%3Dlogin&backTitle=%D0%C2%C0%CB%CE%A2%B2%A9&vt=4&revalid=2&ns=1&pt=1">使用明文密码</a>)<br/><input type="password" name="password_7726" size="30" value=""/><br/><input type="checkbox" name="remember" checked="checked" />记住登录状态,需支持并打开手机的cookie功能。<br/><input type="hidden" name="backURL" value="/dpool/ttt/home.php?s2w=login" /><input type="hidden" name="backTitle" value="新浪微博" /><input type="hidden" name="backURL" value="/dpool/ttt/home.php?s2w=login" /><input type="hidden" name="vk" value="7726_a266_2086017043" /><input type="submit" name="submit" value="登录" /><br/>

使用httpfox(firefox的一个插件)查看登录时浏览器发送的表单数据

最后登录代码如下,下面使用到了Jsoup提取html的标签信息

public boolean Login(String username , String password){String getgsid = null;String content = Get(LoginUrl);if(content==null) return false;Document doc = Jsoup.parse(content); Element form=null , pwnd=null , vk=null;String rand=null , spwnd=null , svk=null;form = doc.select("form[method=post]").first();pwnd = doc.select("input[type=password]").first();vk = doc.select("input[name=vk]").first();if(form==null || pwnd==null || vk==null) return false;rand = form.attr("action");spwnd = pwnd.attr("name");svk = vk.attr("value");if(rand==null || spwnd==null || svk==null) return false;try {String url = "/prog/wapsite/sso/"+rand;HttpPost post = new HttpPost(url);post.setHeader("User-Agent","Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/0101 Firefox/5.0");post.setHeader("Referer", "/");post.setHeader("Content-Type", "application/x-www-form-urlencoded");List<NameValuePair> qparams = new ArrayList<NameValuePair>();qparams.add(new BasicNameValuePair("mobile", username));qparams.add(new BasicNameValuePair(spwnd, password));qparams.add(new BasicNameValuePair("remember", "on"));qparams.add(new BasicNameValuePair("backURL", "/dpool/ttt/home.php"));qparams.add(new BasicNameValuePair("backTitle", "新浪微博"));qparams.add(new BasicNameValuePair("vk", svk));qparams.add(new BasicNameValuePair("submit", "登录"));UrlEncodedFormEntity params = new UrlEncodedFormEntity(qparams, "UTF-8");post.setEntity(params);httpclient.execute(post);post.abort();List<Cookie> cookies = httpclient.getCookieStore().getCookies();if(cookies.size()!=0) getgsid=cookies.get(0).getValue();else getgsid=null;gsid = getgsid;} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch(Exception e){// TODO Auto-generated catch blocke.printStackTrace();} finally{if(gsid==null) return false;else return true;}}

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