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

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

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

    ①用Fiddler2追蹤登錄時(shí)的post請求,發(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,騙過服務(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請求

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

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 久久99精品视免费看| 亚洲免费福利视频| 亚洲一区中文字幕在线电影网| 精品国产福利尤物免费| 免费一级特黄特色大片在线| 亚洲一区二区无码偷拍| 少妇高潮太爽了在线观看免费| 亚洲精品亚洲人成在线麻豆| **真实毛片免费观看| 亚洲成人午夜电影| 日本在线高清免费爱做网站| 亚洲午夜久久久久久尤物| 亚洲Av无码乱码在线播放| 一级做a爰性色毛片免费| 中文字幕一精品亚洲无线一区| 丰满人妻一区二区三区免费视频| 国产亚洲精品拍拍拍拍拍| 国产精成人品日日拍夜夜免费| 亚洲国产人成在线观看69网站 | av在线亚洲欧洲日产一区二区| 成人免费观看男女羞羞视频| 亚洲中文字幕无码一久久区| 国产卡二卡三卡四卡免费网址| 精品人妻系列无码人妻免费视频| 亚洲宅男精品一区在线观看| 国产无遮挡色视频免费视频| 一级毛片免费视频网站| 亚洲一级视频在线观看| 亚洲五月综合缴情在线观看| 99久热只有精品视频免费观看17| 亚洲AV成人噜噜无码网站| 亚洲av永久无码精品秋霞电影影院| 4455永久在线观免费看| 亚洲第一第二第三第四第五第六 | 无码乱人伦一区二区亚洲| 又粗又大又黑又长的免费视频| 黄视频在线观看免费| 国产亚洲精品成人久久网站| 亚洲国产a∨无码中文777| 18禁成年无码免费网站无遮挡| 欧洲精品码一区二区三区免费看|