コード例 #1
0
  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;
  }
コード例 #2
0
  /**
   * @param connection Jsoup connection object
   * @param method HTTP method
   * @return Jsoup Connection.Response object
   */
  public Connection.Response execute(Connection connection, Connection.Method method) {
    Connection.Response response;

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

    try {
      System.out.println("Calling " + connection.request().url());
      if (props.getMode() == Mode.TEST) {
        return null;
      }
      response = connection.execute();
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    }
    this.cookies.putAll(response.cookies());
    return response;
  }