<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ①用Fiddler2追蹤登錄時(shí)的post請(qǐng)求,發(fā)現(xiàn)需要以下參數(shù):

    check

    uname

    backURL

    autoLogin

    pwd

    其中,backURL="/",check=“1”,autoLogin可默認(rèn)為1

    于是,只剩 uname和 pwd

    ②創(chuàng)建一個(gè)HttpClient

    private DefaultHttpClient httpclient = new DefaultHttpClient();

    ③創(chuàng)建一個(gè) HttpPost

    HttpPost httpost = new HttpPost(CommonConst.loginUrl);

    ④偽裝httpost,騙過(guò)服務(wù)器

        /**
         * pretend to be a browser quietly
         
    */
        
    private void setPostHeader(HttpPost post) {
            post.setHeader(CommonConst.UserAgent, CommonConst.HttpAgent);
            post.setHeader(
    "Origin", CommonConst.weiboUrl);
            post.setHeader(
    "Cache-Control""max-age=0");
            post.setHeader(
    "Accept",
                    
    "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            post.setHeader(
    "Accept-Encoding""gzip,deflate,sdch");
            post.setHeader(
    "Accept-Language""en-US,en;q=0.8");
            post.setHeader(
    "Accept-Charset""ISO-8859-1,utf-8;q=0.7,*;q=0.3");
            post.setHeader(
    "Accept-Encoding""gzip,deflate,sdch");
            post.setHeader(
    "Referer", CommonConst.loginUrl);
        }

     ⑤創(chuàng)建NameValuePair

    List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
            nvps.add(
    new BasicNameValuePair("check"this.check));
            nvps.add(
    new BasicNameValuePair("uname"this.uname));
            nvps.add(
    new BasicNameValuePair("backURL"this.backURL));
            nvps.add(
    new BasicNameValuePair("autoLogin"this.autoLogin));
            nvps.add(
    new BasicNameValuePair("pwd"this.pwd));

    ⑥用setEntity方法,給httpost設(shè)置相關(guān)參數(shù)

    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    ⑦向相應(yīng)的host上提交post請(qǐng)求

    HttpHost targetHost = new HttpHost(CommonConst.host);
                response 
    = httpclient.execute(targetHost, httpost);


    login代碼:

    private boolean login() {
            
    // httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
            HttpPost httpost = new HttpPost(CommonConst.loginUrl);
            setPostHeader(httpost);
            
    // All the parameters post to the web site
            List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
            nvps.add(
    new BasicNameValuePair("check"this.check));
            nvps.add(
    new BasicNameValuePair("uname"this.uname));
            nvps.add(
    new BasicNameValuePair("backURL"this.backURL));
            nvps.add(
    new BasicNameValuePair("autoLogin"this.autoLogin));
            nvps.add(
    new BasicNameValuePair("pwd"this.pwd));

            
    try {
                httpost.setEntity(
    new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
                HttpHost targetHost 
    = new HttpHost(CommonConst.host);
                response 
    = httpclient.execute(targetHost, httpost);
            } 
    catch (Exception e) {
                e.printStackTrace();
                
    return false;
            } 
    finally {
                httpost.abort();
            }
            
    return true;
        }


    附CommonConst.java

    package com.yinger;

    public class CommonConst {
        
    public static String HttpAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5";
        
    public static String loginUrl = "http://m.weibo.cn/login";
        
    public static String host = "m.weibo.cn";
        
    public static String weiboUrl = "http://m.weibo.cn";
        
    public static String UserAgent = "User-Agent";
    }



    posted on 2012-07-11 11:59 Ying-er 閱讀(5241) 評(píng)論(5)  編輯  收藏

    評(píng)論:
    # re: 用httpclient模擬瀏覽器,登錄新浪微博 2012-09-11 14:36 |
    能否問(wèn)下,用Fiddler2 如何追蹤到這些參數(shù)的。請(qǐng)教一下  回復(fù)  更多評(píng)論
      
    # re: 用httpclient模擬瀏覽器,登錄新浪微博[未登錄](méi) 2012-11-24 00:17 | tang
    what library should we included in it ?  回復(fù)  更多評(píng)論
      
    # re: 用httpclient模擬瀏覽器,登錄新浪微博 2013-01-06 14:51 | auto714
    HttpClient 開(kāi)源包@tang
      回復(fù)  更多評(píng)論
      
    # re: 用httpclient模擬瀏覽器,登錄新浪微博 2013-01-06 14:52 | auto714
    親!有嘗試過(guò)發(fā)送微博么?  回復(fù)  更多評(píng)論
      
    # re: 用httpclient模擬瀏覽器,登錄新浪微博 2013-01-09 11:04 | restart
    扯呢么,F(xiàn)iddler2 得到的參數(shù),遠(yuǎn)不止這些。  回復(fù)  更多評(píng)論
      

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲综合成人婷婷五月网址| 伊人久久大香线蕉免费视频| 亚洲国产精品婷婷久久| 免费a在线观看播放| 成视频年人黄网站免费视频| 一区二区三区无码视频免费福利| 亚洲AV第一成肉网| 亚洲AV无码一区二区三区在线 | 日本一区二区三区在线视频观看免费| 亚洲男人的天堂在线| 国产亚洲精品精华液| 亚洲人AV永久一区二区三区久久| 日本一道综合久久aⅴ免费| 日韩免费一区二区三区在线播放| 久久久久成人精品免费播放动漫| 一级成人a做片免费| 免费在线观看一区| 狠狠入ady亚洲精品| 亚洲综合av一区二区三区不卡 | 午夜精品一区二区三区免费视频| sihu国产精品永久免费| 色老头综合免费视频| 色欲aⅴ亚洲情无码AV| 亚洲爆乳少妇无码激情| 亚洲AV综合色区无码一二三区| 亚洲色欲色欲www| 亚洲精品国产国语| 亚洲日日做天天做日日谢| 2020国产精品亚洲综合网| 亚洲视频在线观看2018| 亚洲男人天堂2018av| 久久亚洲精品国产亚洲老地址| 精品久久久久久亚洲精品| 亚洲国产激情在线一区| 亚洲人成综合网站7777香蕉| 亚洲啪AV永久无码精品放毛片| 亚洲欧美日韩一区二区三区 | 性感美女视频免费网站午夜| 亚洲免费观看视频| 久久国产免费一区二区三区 | 亚洲av成人无码久久精品|