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

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


    網站導航:
     
    主站蜘蛛池模板: 四虎永久精品免费观看| 久久久亚洲精品国产| 波多野结衣亚洲一级| 亚洲日本国产乱码va在线观看| 久青草视频97国内免费影视| 国产亚洲精品拍拍拍拍拍| 亚洲伦理中文字幕| 最近中文字幕无吗高清免费视频| 亚洲最大的成人网| 中国黄色免费网站| 久久青青草原亚洲AV无码麻豆| 国产成人无码区免费网站| 亚洲国产高清在线| 特级毛片免费观看视频| 亚洲国产av无码精品| 一区二区三区免费在线观看| 成年女人18级毛片毛片免费观看| 亚洲人成网站在线播放2019| 国产一区二区三区免费在线观看| 精品在线视频免费| 亚洲精品成人网站在线观看| 亚洲人成人无码.www石榴| 免费又黄又爽的视频| 国产高潮流白浆喷水免费A片 | 日韩免费在线观看| 中文有码亚洲制服av片| 四虎永久精品免费观看| 久久精品成人免费看| 亚洲成人激情小说| 久久99亚洲综合精品首页| 99爱视频99爱在线观看免费| 2020天堂在线亚洲精品专区| 亚洲国产精品碰碰| 亚洲精品国产免费| 日本系列1页亚洲系列| 精品国产亚洲一区二区三区| 国产精品69白浆在线观看免费| 亚洲毛片免费观看| 久久精品国产免费观看| 高潮毛片无遮挡高清免费视频| 亚洲成a人片77777老司机|