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

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

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

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

    check

    uname

    backURL

    autoLogin

    pwd

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

    于是,只剩 uname和 pwd

    ②創(chuàng)建一個HttpClient

    private DefaultHttpClient httpclient = new DefaultHttpClient();

    ③創(chuàng)建一個 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久久成人国产精品免费| 亚洲国产精品无码中文lv| 国产乱子伦精品免费视频| 丁香亚洲综合五月天婷婷| 在线亚洲v日韩v| 亚洲一级毛片中文字幕| 91免费人成网站在线观看18| 亚洲综合区图片小说区| 国产2021精品视频免费播放| 亚洲av成人一区二区三区| 午夜免费福利影院| 国产午夜亚洲精品不卡免下载| 国产午夜鲁丝片AV无码免费| 无套内谢孕妇毛片免费看看| 亚洲国产精品成人久久蜜臀| 久久av免费天堂小草播放| 亚洲成色在线综合网站| 99在线视频免费| 国产国产成年年人免费看片| 精品久久久久久久久亚洲偷窥女厕| 国产午夜免费秋霞影院| 久久久久女教师免费一区| 久久精品国产96精品亚洲| 国产精品亚洲а∨无码播放不卡 | a级亚洲片精品久久久久久久| 国产免费伦精品一区二区三区| 亚洲av无码片在线播放| 国产精品成人观看视频免费 | 亚洲色图黄色小说| 国产伦精品一区二区免费| 亚洲精品无码成人AAA片| 亚洲人成在线免费观看| 亚洲国产成人久久精品软件| 亚洲深深色噜噜狠狠爱网站| 老外毛片免费视频播放| 亚洲午夜福利AV一区二区无码| 又大又硬又爽又粗又快的视频免费| 亚洲AV乱码一区二区三区林ゆな| 一色屋成人免费精品网站| 亚洲精品美女在线观看| 国产午夜无码视频免费网站|