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

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

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

    ①用Fiddler2追蹤登錄時的post請求,發現需要以下參數:

    check

    uname

    backURL

    autoLogin

    pwd

    其中,backURL="/",check=“1”,autoLogin可默認為1

    于是,只剩 uname和 pwd

    ②創建一個HttpClient

    private DefaultHttpClient httpclient = new DefaultHttpClient();

    ③創建一個 HttpPost

    HttpPost httpost = new HttpPost(CommonConst.loginUrl);

    ④偽裝httpost,騙過服務器

        /**
         * 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);
        }

     ⑤創建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設置相關參數

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

    ⑦向相應的host上提交post請求

    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 閱讀(5243) 評論(5)  編輯  收藏

    評論:
    # re: 用httpclient模擬瀏覽器,登錄新浪微博 2012-09-11 14:36 |
    能否問下,用Fiddler2 如何追蹤到這些參數的。請教一下  回復  更多評論
      
    # re: 用httpclient模擬瀏覽器,登錄新浪微博[未登錄] 2012-11-24 00:17 | tang
    what library should we included in it ?  回復  更多評論
      
    # re: 用httpclient模擬瀏覽器,登錄新浪微博 2013-01-06 14:51 | auto714
    HttpClient 開源包@tang
      回復  更多評論
      
    # re: 用httpclient模擬瀏覽器,登錄新浪微博 2013-01-06 14:52 | auto714
    親!有嘗試過發送微博么?  回復  更多評論
      
    # re: 用httpclient模擬瀏覽器,登錄新浪微博 2013-01-09 11:04 | restart
    扯呢么,Fiddler2 得到的參數,遠不止這些。  回復  更多評論
      

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 四虎影在线永久免费观看| 中文字幕免费在线观看| 日本人护士免费xxxx视频| 亚洲女人18毛片水真多| 在线观看的免费网站无遮挡| 午夜影视日本亚洲欧洲精品一区| 九九九精品视频免费| 红杏亚洲影院一区二区三区| yellow免费网站| 亚洲精品午夜无码专区| 免费av一区二区三区| 内射干少妇亚洲69XXX| 99国产精品永久免费视频| 国产精品亚洲精品| 成年女人毛片免费播放人| 青青青亚洲精品国产| 亚洲国产精品综合久久网络| 中文字幕版免费电影网站| 少妇中文字幕乱码亚洲影视| 亚洲一区二区三区免费观看| 国产亚洲福利在线视频| 亚洲AV伊人久久青青草原| a毛片在线免费观看| 亚洲av永久综合在线观看尤物| 国产麻豆免费观看91| 中国毛片免费观看| 亚洲美女色在线欧洲美女| 国内自产拍自a免费毛片| 另类图片亚洲校园小说区| 国产亚洲免费的视频看| av无码国产在线看免费网站| 久久亚洲精品无码网站| 亚洲成av人片一区二区三区| 久久免费国产视频| 亚洲乱码日产精品一二三| 亚洲日本乱码在线观看| 精品久久久久久久久免费影院| 特级毛片aaaa级毛片免费| 亚洲精品美女久久久久9999| 免费不卡中文字幕在线| 国产精品99精品久久免费|