<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 閱讀(5242) 評論(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 得到的參數,遠不止這些。  回復  更多評論
      

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲AV无码精品蜜桃| 亚洲中文字幕在线乱码| 亚洲精品福利网泷泽萝拉| 9i9精品国产免费久久| 亚洲中文久久精品无码ww16| 日韩一区二区三区免费播放| 免费观看日本污污ww网站一区| 亚洲av日韩综合一区久热| 成年在线观看免费人视频草莓| 亚洲一级片在线观看| 久久久www成人免费毛片| 亚洲乱码一二三四五六区| 免费H网站在线观看的| 亚洲国产av一区二区三区丶| 18禁免费无码无遮挡不卡网站 | 杨幂最新免费特级毛片| 国产成人精品日本亚洲专区| GOGOGO高清免费看韩国| 国产亚洲精品一品区99热| 8x8×在线永久免费视频| 亚洲国产成+人+综合| 天天拍拍天天爽免费视频| 亚洲成熟丰满熟妇高潮XXXXX| 免费国产在线观看老王影院| 免费福利资源站在线视频| 亚洲乱码一区二区三区在线观看 | 亚洲理论片在线中文字幕| 亚洲免费网站观看视频| 99亚洲精品卡2卡三卡4卡2卡| av在线亚洲欧洲日产一区二区| 亚洲精品免费视频| 亚洲已满18点击进入在线观看| 国产精品酒店视频免费看| 黄色视屏在线免费播放| 亚洲色偷偷偷网站色偷一区| a级毛片无码免费真人| 日本视频免费观看| 中文字幕亚洲综合久久2| 蜜臀91精品国产免费观看| 成年女人A毛片免费视频| tom影院亚洲国产一区二区|