private static Response execute(
      String url, Method method, Map<String, String> cookies, Map<String, String> data) {
    Response response = null;

    Connection connection = Jsoup.connect(url);
    connection.method(method);

    connection.timeout(10000);
    connection.ignoreContentType(true);
    connection.maxBodySize(0);

    if (cookies != null) {
      connection.cookies(cookies);
    }

    if (data != null) {
      for (Entry<String, String> entry : data.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        connection.data(key, value);
      }
    }

    try {
      response = connection.execute();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return response;
  }
Example #2
0
 public boolean loginBySavedCookies() {
   loginCookies.clear();
   readCookies(EzraPoundUtil.LOGIN_COOKIES_DIR, loginCookies);
   Connection con = JsoupUtil.getGetCon("https://www.zhihu.com");
   Response rs = null;
   try {
     rs = con.cookies(loginCookies).execute();
   } catch (IOException e) {
     e.printStackTrace();
     log.info("携带cookie登录测试失败");
     return false;
   }
   return checkLogin(Jsoup.parse(rs.body()));
 }