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

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

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

    athrunwang

    紀元
    數據加載中……
    HttpClient 對 cookie 的處理
    public static void main(String[] args) {
            HttpClient client = new HttpClient();
            NameValuePair[] nameValuePairs = {
                    new NameValuePair("username", "aaa"),
                    new NameValuePair("passwd", "123456")
            };
            PostMethod postMethod = new PostMethod("登錄url");
            postMethod.setRequestBody(nameValuePairs);
            int stats = 0;
            try {
                stats = client.executeMethod(postMethod);
            } catch (HttpException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            postMethod.releaseConnection();//這里最好把之前的資源放掉
            CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
            Cookie[] cookies = cookiespec.match("域名", 80/*端口*/, "/" , false , client.getState().getCookies());
            for (Cookie cookie : cookies) {
                System.out.println(cookie.getName() + "##" + cookie.getValue());
            }
            
            HttpMethod method = null;
            String encode = "utf-8";//頁面編碼,按訪問頁面改動
            String referer = "http://域名";//http://www.163.com
            method = new GetMethod("url2");//后續操作
            method.getParams().setParameter("http.useragent","Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)");
            method.setRequestHeader("Referer", referer);

            client.getParams().setContentCharset(encode);
            client.getParams().setSoTimeout(300000);
            client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(10, true));
     
            try {
                stats = client.executeMethod(method);
            } catch (HttpException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (stats == HttpStatus.SC_OK) {
                System.out.println("提交成功!");
                
            }
        }

    posted on 2011-12-28 20:51 AthrunWang 閱讀(2398) 評論(0)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 日本黄页网址在线看免费不卡 | 午夜私人影院免费体验区| 国产AV无码专区亚洲精品| 成全视成人免费观看在线看| 怡红院亚洲怡红院首页| eeuss影院ss奇兵免费com| 国产AV无码专区亚洲AV漫画| 国产一级在线免费观看| 亚洲处破女AV日韩精品| 无码日韩精品一区二区三区免费| 亚洲AV无码一区东京热| 99久在线国内在线播放免费观看| 亚洲尹人九九大色香蕉网站| 中文字幕无码播放免费| 亚洲一区二区久久| 卡1卡2卡3卡4卡5免费视频| 亚洲国产高清国产拍精品| 免费成人黄色大片| 中文字幕av免费专区| 亚洲免费在线视频| 国产一卡2卡3卡4卡2021免费观看| 亚洲日韩国产二区无码| 免费在线观看污网站| 你懂的在线免费观看| 亚洲国产精品综合福利专区| 免费看片免费播放| 一级毛片免费视频网站| 亚洲色图在线观看| 性色av免费观看| CAOPORN国产精品免费视频| 亚洲一级二级三级不卡| 日本免费一区尤物| 中文字幕无码一区二区免费| 亚洲五月综合缴情婷婷| 亚洲日韩国产精品乱| 最刺激黄a大片免费网站| 亚洲国产成人手机在线观看| 亚洲日韩激情无码一区| 国内免费高清在线观看| 福利免费在线观看| 亚洲中文无码卡通动漫野外|