zoukankan      html  css  js  c++  java
  • 第一次调用从server获取Cookie

    System.setProperty("javax.net.ssl.trustStore", certPath);

    public String getCookieString(String userId, String pwd) throws Exception {

    HttpClient httpclient = HttpClientBuilder.create().build();

    HttpPost httpPost = new HttpPost(LONGIN_URL);

    httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    httpPost.setEntity(getParam(userId, pwd));

    HttpResponse response = httpclient.execute(httpPost);

    return _getCookieString(response.getAllHeaders());

    }

    private String _getCookieString(Header[] h) {

    String cookieFromServer = "";

    for (Header ibh : h) {
    System.out.print(ibh.getName());
    if (ibh.getName().equals("Set-Cookie")) {
    cookieFromServer = cookieFromServer + ibh.getValue();
    }
    }

    return cookieFromServer;
    }

    private StringEntity getParam(String userName, String pwd) {

    String aa = "username=" + userName + "&password=" + pwd + "&requestedHash=";

    StringEntity requestEntity = new StringEntity(aa, ContentType.APPLICATION_FORM_URLENCODED);
    return requestEntity;
    }

  • 相关阅读:
    Object-C 声明属性为什么用下划线,代码规范和编程风格
    iOS API 概述
    iOS 彻底学会使用delegate
    iOS NSNotification的使用
    L1_6 连续因子
    天梯 L1_46整除光棍
    51-Nod 1279
    UVA
    hdu 1078
    Poj 1088 滑雪 递归实现
  • 原文地址:https://www.cnblogs.com/wblade/p/6363118.html
Copyright © 2011-2022 走看看