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

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

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

Connection.ignoreContentType介绍

[英]Ignore the document's Content-Type when parsing the response. By default this is false, an unrecognised content-type will cause an IOException to be thrown. (This is to prevent producing garbage by attempting to parse a JPEG binary image, for example.) Set to true to force a parse attempt regardless of content type.
[中]解析响应时忽略文档的内容类型。默认情况下,这是false,无法识别的内容类型将导致引发IOException。(例如,这是为了防止试图解析JPEG二进制图像而产生垃圾。)设置为true以强制进行解析尝试,而不考虑内容类型。

代码示例

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

public Http ignoreContentType() {
  connection.ignoreContentType(true);
  return this;
}
public Http referrer(String ref)  {

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

.connect("https://vk.com/al_photos.php")
.header("Referer", this.url.toExternalForm())
.ignoreContentType(true)
.userAgent(USER_AGENT)
.timeout(5000)

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

Response response;
response = Jsoup.connect(updateJarURL)
    .ignoreContentType(true)
    .timeout(Utils.getConfigInteger("download.timeout", 60 * 1000))
    .maxBodySize(1024 * 1024 * 100)

代码示例来源:origin: ChinaSilence/any-video

public static Document getDocWithPC(String url) {
  try {
    return Jsoup.connect(url).userAgent(UA_PC).timeout(TIME_OUT).ignoreContentType(true).get();
  } catch (IOException e) {
    log.error(ERROR_DESC + url);
    throw new AnyException(ERROR_DESC + url);
  }
}

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

doc = Jsoup.connect(UpdateUtils.updateJsonURL)
        .timeout(10 * 1000)
        .ignoreContentType(true)
        .get();
} catch (IOException e) {

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

doc = Jsoup.connect(UpdateUtils.updateJsonURL)
      .timeout(10 * 1000)
      .ignoreContentType(true)
      .get();
} catch (IOException e) {

代码示例来源:origin: ChinaSilence/any-video

public static Document getDocWithPhone(String url) {
  try {
    return Jsoup.connect(url).userAgent(UA_PHONE).timeout(TIME_OUT).ignoreContentType(true).validateTLSCertificates(false).get();
  } catch (IOException e) {
    log.error(ERROR_DESC + url);
    throw new AnyException(ERROR_DESC + url);
  }
}

代码示例来源:origin: ChinaSilence/any-video

public static Document getDocWithPhone(String url, String cookie) {
  try {
    return Jsoup.connect(url).userAgent(UA_PHONE).timeout(TIME_OUT).header("Cookie", cookie).ignoreContentType(true).get();
  } catch (IOException e) {
    log.error(ERROR_DESC + url);
    throw new AnyException(ERROR_DESC + url);
  }
}

代码示例来源:origin: ChinaSilence/any-video

/**
   * 获取片段播放的 key
   */
  private String videoKey(String vid, String filename, String format) {
    try {
      Document document = Jsoup.connect(KEY_API).header("Cookie", COOKIE)
          .data("vid", vid).data("platform", PLATFORM)
          .data("otype", "json")
          .data("filename", filename).data("sdtfrom", SDTFROM)
          .data("format", format).data("guid", GUID).ignoreContentType(true).get();
      String result = document.text().replace("QZOutputJson=", "");
      System.out.println(result);
      result = result.substring(0, result.length() - 1);
      return JSONObject.parseObject(result).getString("key");
    } catch (IOException e) {
      log.info("request tencent video part api error, vid : " + vid);
      throw new AnyException("request tencent api error, vid : " + vid);
    }
  }
}

代码示例来源:origin: ChinaSilence/any-video

private Document requestAPI(String keyword) {
  try {
    return Jsoup.connect(api).userAgent(ua).ignoreContentType(true).data("wd", keyword).get();
  } catch (IOException e) {
    throw new AnyException(ExceptionEnum.VIDEO_SEARCH_ERROR);
  }
}

代码示例来源:origin: ChinaSilence/any-video

/**
 * 调用腾讯接口,获取视频信息
 */
private String videoInfo(String vid) {
  try {
    Document document = Jsoup.connect(VIDEO_API).header("Cookie", COOKIE)
        .data("vids", vid).data("platform", PLATFORM)
        .data("sdtfrom", SDTFROM)
        .data("format", "10209")
        .data("otype", "json").data("defn", "fhd")
        .data("defaultfmt", "fhd").data("guid", GUID).ignoreContentType(true).get();
    String result = document.text().replace("QZOutputJson=", "");
    return result.substring(0, result.length() - 1);
  } catch (IOException e) {
    log.info("request tencent api error, vid : " + vid);
    throw new AnyException("request tencent api error, vid : " + vid);
  }
}

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

@Override
  public Connection.Request buildRequest(@NonNull Movie movie) {
    val searchLink = "http://www.omdbapi.com";
    val queryParams = new ImmutableMap.Builder<String, String>()
        .put("t", movie.getTitle())
        .put("plot", "short")
        .put("r", "json")
        .build();

    return HttpConnection.connect(HttpUtils.buildURL(searchLink, queryParams))
        .ignoreContentType(true)
        .request();
  }
}

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

@Override
protected void processHeader(RequestModel model) {
  Map<String, String> headers = model.getHeaders();
  if(headers != null && headers.get("Content-Type") == null) {
    connection.ignoreContentType(true);
  }
  connection.headers(model.getHeaders());
}

代码示例来源:origin: crazyhitty/Munch

@Override
protected String doInBackground(String... strings) {
  try {
    Document rssDocument = Jsoup.connect(mUrl).ignoreContentType(true).parser(Parser.xmlParser()).get();
    mItems = rssDocument.select("item");
  } catch (IOException e) {
    e.printStackTrace();
    return "failure";
  }
  return "success";
}

代码示例来源:origin: SudaVideo/MyVideoApi

public static Document getDocWithPC(String url) {
  try {
    return Jsoup.connect(url).userAgent(UA_PC).timeout(TIME_OUT).ignoreContentType(true).get();
  } catch (IOException e) {
    log.error(ERROR_DESC + url);
    throw new BizException(BizErrorCodeConstants.S0002, e);
  }
}

代码示例来源:origin: SudaVideo/MyVideoApi

public static Document getDocWithPhone(String url) {
    try {
      return Jsoup.connect(url).userAgent(UA_PHONE).timeout(TIME_OUT).ignoreContentType(true).validateTLSCertificates(false).get();
    } catch (IOException e) {
      log.error(ERROR_DESC + url);
      throw new BizException(BizErrorCodeConstants.S0002, 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: BeelGroup/Docear-Desktop

protected Connection getConnection(String URL) {		
  return Jsoup.connect(URL)				   
        .ignoreContentType(true)
        .userAgent(this.userAgent)  
        .referrer(this.referrer)   
        .timeout(this.timeout) 
        .followRedirects(this.followRedirects);		           
}

代码示例来源:origin: Patreon/patreon-java

public TokensResponse refreshTokens(String refreshToken) throws IOException {
 Connection requestInfo = Jsoup.connect(PatreonAPI.BASE_URI + "/api/oauth2/token")
               .data("grant_type", GRANT_TYPE_TOKEN_REFRESH)
               .data("client_id", clientID)
               .data("client_secret", clientSecret)
               .data("refresh_token", refreshToken)
               .ignoreContentType(true);
 String response = requestInfo.post().body().text();
 return toObject(response, TokensResponse.class);
}

代码示例来源:origin: Patreon/patreon-java

public TokensResponse getTokens(String code) throws IOException {
 Connection requestInfo = Jsoup.connect(PatreonAPI.BASE_URI + "/api/oauth2/token")
               .data("grant_type", GRANT_TYPE_AUTHORIZATION)
               .data("code", code)
               .data("client_id", clientID)
               .data("client_secret", clientSecret)
               .data("redirect_uri", redirectUri)
               .ignoreContentType(true);
 String response = requestInfo.post().body().text();
 return toObject(response, TokensResponse.class);
}

相关文章