org.jsoup.Connection.method()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中org.jsoup.Connection.method()方法的一些代码示例,展示了Connection.method()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.method()方法的具体详情如下:
包路径:org.jsoup.Connection
类名称:Connection
方法名:method

Connection.method介绍

[英]Set the request method to use, GET or POST. Default is GET.
[中]将请求方法设置为use、GET或POST。默认值是GET。

代码示例

代码示例来源:origin: RipMeApp/ripme

public Http method(Method method) {
  connection.method(method);
  return this;
}

代码示例来源:origin: RipMeApp/ripme

public Document post() throws IOException {
  connection.method(Method.POST);
  return response().parse();
}

代码示例来源:origin: RipMeApp/ripme

public Document get() throws IOException {
  connection.method(Method.GET);
  return response().parse();
}

代码示例来源:origin: RipMeApp/ripme

private void defaultSettings() {
  this.retries = Utils.getConfigInteger("download.retries", 1);
  connection = Jsoup.connect(this.url);
  connection.userAgent(AbstractRipper.USER_AGENT);
  connection.method(Method.GET);
  connection.timeout(TIMEOUT);
  connection.maxBodySize(0);
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Prepare to submit this form. A Connection object is created with the request set up from the form values. You
 * can then set up other options (like user-agent, timeout, cookies), then execute it.
 * @return a connection prepared from the values of this form.
 * @throws IllegalArgumentException if the form's absolute action URL cannot be determined. Make sure you pass the
 * document's base URI when parsing.
 */
public Connection submit() {
  String action = hasAttr("action") ? absUrl("action") : baseUri();
  Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing.");
  Connection.Method method = attr("method").toUpperCase().equals("POST") ?
      Connection.Method.POST : Connection.Method.GET;
  return Jsoup.connect(action)
      .data(formData())
      .method(method);
}

代码示例来源:origin: YuanKJ-/JsCrawler

@Override
protected void processMethod(RequestModel model) {
  String method = model.getMethod();
  if("POST".equals(method)) {
    connection.method(Connection.Method.POST);
  }else{
    connection.method(Connection.Method.GET);
  }
}

代码示例来源:origin: AlexanderBartash/hybris-integration-intellij-idea-plugin

protected Response getResponseForUrl(String hacURL) {
  try {
    return connect(hacURL).method(Method.GET).execute();
  } catch (ConnectException ce) {
    return null;
  } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
    LOG.warn(e.getMessage(), e);
    return null;
  }
}

代码示例来源:origin: bluetata/crawler-jsoup-maven

public static void main(String[] args) {
  // grab login form page first
  try {
    
    //lets make data map containing all the parameters and its values found in the form
    Map<String, String> mapParamsData = new HashMap<String, String>();
    mapParamsData.put("email", "dietime1943@bluetata.com");
    mapParamsData.put("password", "bluetata");
    
    Response loginResponse = Jsoup.connect("https://passport.jd.com/new/login.aspx")
        .userAgent(USER_AGENT)
        .timeout(TIMEOUT_UNIT * TIMEOUT_TIMES)
        .data(mapParamsData)
        .method(Method.POST)
        .followRedirects(true)
        .execute();
    
    System.out.println("Fetched login page");
    // System.out.println(loginResponse.toString());
    
   //get the cookies from the response, which we will post to the action URL
    Map<String, String> mapLoginPageCookies = loginResponse.cookies();
    
    System.out.println(mapLoginPageCookies);
    
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: REDNBLACK/J-Kinopoisk2IMDB

/**
   * Sends POST request and adds Movie to IMDB list, using {@link Movie#imdbId}
   *
   * @param movie Movie which should be added to IMDB list
   * @throws IOException If an I/O error occurs
   */
  @Override
  public ExchangeObject<Integer> prepare(@NonNull Movie movie) throws IOException {
    val movieAddToWatchlistLink = new URL("http://www.imdb.com/list/_ajax/edit");

    val postData = new ImmutableMap.Builder<String, String>()
        .put("const", movie.getImdbId())
        .put("list_id", config.getString("list"))
        .put("ref_tag", "title")
        .build();

    val request = HttpConnection.connect(movieAddToWatchlistLink)
        .method(Connection.Method.POST)
        .userAgent(config.getString("user_agent"))
        .timeout(config.getInt("timeout"))
        .cookie("id", config.getString("auth"))
        .ignoreContentType(true)
        .data(postData)
        .request();

    return new ExchangeObject<>(request, new JSONPOSTResponseProcessor());
  }
}

代码示例来源:origin: YuanKJ-/JsCrawler

@Override
protected void processBody(RequestModel model) {
  if(model.getBody() != null) {
    connection.method(Connection.Method.POST);
    connection.header("Content-Type", "application/json");
    connection.requestBody(model.getBody());
  }
}

代码示例来源:origin: REDNBLACK/J-Kinopoisk2IMDB

.method(Connection.Method.POST)
.userAgent(config.getString("user_agent"))
.timeout(config.getInt("timeout"))

代码示例来源:origin: bluetata/crawler-jsoup-maven

.timeout(TIMEOUT_UNIT * TIMEOUT_TIMES)
.data(mapParamsData)
.method(Method.POST)
.followRedirects(true)
.execute();

代码示例来源:origin: delthas/JavaSkype

private String getToken(String token, String scope) throws IOException {
 Response response = Jsoup.connect(SERVER_HOSTNAME + "/oauth20_token.srf").data("client_id", "00000000480BC46C", "scope", scope, "grant_type", "refresh_token", "refresh_token", token).maxBodySize(100 * 1024 * 1024).timeout(10000).method(Method.POST).ignoreContentType(true).ignoreHttpErrors(true).execute();
 if (response.statusCode() != 200) {
  try {
   JSONObject json = new JSONObject(response.body());
   String errorDescription = json.getString("error_description");
   IOException ex = new IOException("Error while connecting to Live: token request error: " + errorDescription);
   logger.log(Level.SEVERE, "", ex);
   throw ex;
  } catch (JSONException | IllegalFormatException e) {
   IOException ex = new IOException("Error while connecting to Live: unknown token request error: " + response.body());
   logger.log(Level.SEVERE, "", ex);
   throw ex;
  }
 }
 try {
  JSONObject json = new JSONObject(response.body());
  String accessToken = json.getString("access_token");
  return accessToken;
 } catch (JSONException | IllegalFormatException e) {
  IOException ex = new IOException("Error while connecting to Live: failed reading token response: " + response.body());
  logger.log(Level.SEVERE, "", ex);
  throw ex;
 }
}

代码示例来源:origin: wzypandaking/rbac-shiro

private String request(String api, Map<String, Object> param) {
  String url = String.format("%s/client/api/%s", rbacShiroUrl, api);
  try {
    Connection.Response response = Jsoup.connect(url)
        .method(Connection.Method.POST)
        .timeout(300)
        .data(ImmutableMap.of(
        "code", URLEncoder.encode(RSAUtil.encrypt(param, publicKey), "UTF-8"),
        "uuid", uuid,
        "licenseKey", licenseKey
        )).ignoreContentType(true)
        .execute();
    JSONObject object = JSONObject.parseObject(response.body(), JSONObject.class);
    if (!object.getBoolean("success")) {
      throw new AuthenticationException(response.body());
    }
    String data = object.getString("data");
    JSONObject client = JSON.parseObject(data);
    String encryptKey = client.getString("key");
    byte[] jsonBytes = RSAUtil.decrypt(Base64.getDecoder().decode(encryptKey), publicKey);
    String key = new String(jsonBytes, "UTF-8");
    return DESUtil.decrypt(client.getString("code"), key);
  } catch (Exception e) {
    throw new AuthenticationException("请求异常", e);
  }
}

代码示例来源:origin: delthas/JavaSkype

private Response sendRequest(Method method, String apiPath, boolean absoluteApiPath, String... keyval) throws IOException {
 String url = absoluteApiPath ? apiPath : SERVER_HOSTNAME + apiPath;
 Connection conn = Jsoup.connect(url).maxBodySize(100 * 1024 * 1024).timeout(10000).method(method).ignoreContentType(true).ignoreHttpErrors(true);
 logger.finest("Sending " + method + " request at " + url);
 if (skypeToken != null) {
  conn.header("X-Skypetoken", skypeToken);
 } else {
  logger.fine("No token sent for the request at: " + url);
 }
 conn.data(keyval);
 return conn.execute();
}

代码示例来源:origin: dimtion/Shaarlier

/**
 * Helper method which create a new connection to Shaarli
 * @param url the url of the shaarli
 * @param isPost true if we create a POST request, false for a GET request
 * @return pre-made jsoupConnection
 */
private Connection createShaarliConnection(String url, boolean isPost){
  Connection jsoupConnection = Jsoup.connect(url);
  Connection.Method connectionMethod = isPost ? Connection.Method.POST : Connection.Method.GET;
  if (!"".equals(this.mBasicAuth)) {
    jsoupConnection = jsoupConnection.header("Authorization", "Basic " + this.mBasicAuth);
  }
  if (this.mCookies != null){
    jsoupConnection = jsoupConnection.cookies(this.mCookies);
  }
  return jsoupConnection
      .validateTLSCertificates(this.mValidateCert)
      .timeout(this.mTimeout)
      .followRedirects(true)
      .method(connectionMethod);
}

代码示例来源:origin: bluetata/crawler-jsoup-maven

static Map<String,String> connect() throws IOException{
    Connection.Response res = Jsoup.connect("https://www.facebook.com/login.php")
        .data("username", "dietime1943@hotmail.com", "password", "password")
        .timeout(30 * 1000)
        .userAgent("Mozilla/5.0")
        .method(Method.POST)
        .execute();
    Document doc = res.parse();
    System.out.println(doc);
    
    Map<String, String> loginCookies = res.cookies();
    String sessionId = res.cookie("SESSIONID");
    return loginCookies;
  }
}

代码示例来源:origin: malmstein/yahnac

public Connection loginConnection(String username, String password) {
  Connection login = connection(LOGIN_BASE_URL);
  return login
      .data("go_to", "news")
      .data("acct", username)
      .data("pw", password)
      .header("Origin", ConnectionProvider.BASE_URL)
      .followRedirects(true)
      .referrer(ConnectionProvider.BASE_URL + ConnectionProvider.LOGIN_URL_EXTENSION)
      .method(Connection.Method.POST);
}

代码示例来源:origin: bluetata/crawler-jsoup-maven

public static void main(String[] args) throws IOException {
  try {
    String url = "https://www.oschina.net/home/login";
    String userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36";
    Connection.Response response = Jsoup.connect(url).userAgent(userAgent).method(Connection.Method.GET)
        .execute();
    response = Jsoup.connect(url).cookies(response.cookies()).userAgent(userAgent)
        .referrer("https://www.oschina.net/home/login?goto_page=https%3A%2F%2Fmy.oschina.net%2Fbluetata")
        .data("username", "dietime1943@hotmail.com", "password", "lvmeng152300").data("save_login", "1")
        .followRedirects(false)
        .method(Connection.Method.POST).followRedirects(true).timeout(30 * 1000).execute();
    System.err.println(response.statusCode());
    
    Document doc = Jsoup.connect("https://my.oschina.net/bluetata").cookies(response.cookies())
        .userAgent(userAgent).timeout(30 * 1000).get();
    System.out.println(doc);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: bluetata/crawler-jsoup-maven

.method(Connection.Method.GET).execute();
    .referrer("https://www.oschina.net/home/login")
    .data("username", "dietime1943@hotmail.com", "password", "lvmeng152300").data("save_login", "1")
    .timeout(30 * 1000).cookies(loginForm.cookies()).method(Method.POST).execute();
Document doc = res.parse();
System.out.println(doc);

相关文章