<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成人无码网站| 国产又大又粗又硬又长免费| 亚洲中文字幕无码爆乳av中文 | 亚洲熟妇无码八AV在线播放| 亚洲av无码一区二区三区天堂 | 亚洲色成人四虎在线观看| 美女视频黄的全免费视频网站| 91亚洲一区二区在线观看不卡| 91av免费观看| 亚洲精品综合一二三区在线| 久久免费美女视频| 久久精品国产亚洲精品2020| 亚洲精品在线免费观看视频| 久久亚洲精品成人无码网站| 成年人视频免费在线观看| 亚洲国产高清视频在线观看| 国产福利在线免费| 亚洲综合校园春色| 日本一道一区二区免费看| 男男黄GAY片免费网站WWW| 免费一级毛片女人图片| 一级毛片免费观看不收费| 亚洲桃色AV无码| 最近免费中文字幕高清大全| 亚洲一区二区三区久久| 国产人成免费视频| 一级一片免费视频播放| 亚洲丁香色婷婷综合欲色啪| 免费观看的毛片大全| 亚洲小说图区综合在线| 亚洲精品无码日韩国产不卡?V| 成人无码视频97免费| 亚洲综合图片小说区热久久| 毛片在线看免费版| 特a级免费高清黄色片| 精品亚洲综合久久中文字幕| 999久久久免费精品国产 | 一级做a爰片久久毛片免费陪| 亚洲精品午夜无码电影网| 四虎在线免费视频| 免费国产污网站在线观看不要卡|