Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Http 416,请求的范围不可满足_Java_Jsoup_Httpclient - Fatal编程技术网

Java Http 416,请求的范围不可满足

Java Http 416,请求的范围不可满足,java,jsoup,httpclient,Java,Jsoup,Httpclient,我正在使用http客户端获取数据: public static String getHttpResponse(String url) { //LOGGER.info("Download page context from URL " + url); String httpClientResponse = null; try { URI uri = new URIBuilder(url).build(); HttpResponse response; HttpHost target

我正在使用http客户端获取数据:

public static String getHttpResponse(String url) {

//LOGGER.info("Download page context from URL " + url);
String httpClientResponse = null;
try {
  URI uri = new URIBuilder(url).build();
  HttpResponse response;

  HttpHost target = new HttpHost(uri.getHost());
  HttpGet request = new HttpGet(uri);

  //request.setConfig(config);
  request.addHeader(new BasicHeader("User-Agent", "Mozilla/5.0"));
  request.addHeader(new BasicHeader("Content-Type", "text/html"));
  request.addHeader("Accept-Ranges", "bytes=100-1500");

  org.apache.http.client.HttpClient
      client = HttpClients.custom().build();

  response = client.execute(target, request);

  //LOGGER.info("Status Line for URL {} is {}", uri.getHost() + File.separator + uri.getPath(), response.getStatusLine());

  InputStream inputStream = response.getEntity().getContent();

  if (inputStream == null || response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
    /*LOGGER.error("Non-success response while downloading image. Response {}", response.getStatusLine());
    LOGGER.error("Error while download data from url {}", url);*/
  } else {
    httpClientResponse = IOUtils.toString(inputStream, CharEncoding.UTF_8);
  }

} catch (Exception e) {
  System.out.println("Error while download content from URL");
}
return httpClientResponse;
}
另外:我们可以使用Jsoup来实现这一点吗

谢谢。

更换:

request.addHeader("Accept-Ranges", "bytes=100-1500");
与:

request.addHeader("Range", "bytes=100-1500");
Accept Ranges标头是服务器响应的一部分,表示服务器接受部分请求

在您的请求中,您应该使用范围标头,它指示应该返回文档服务器的哪个部分


好的,但我应该给出什么字节范围?