Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.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 找不到HttpClient间歇页面_Java_Apache Httpclient 4.x - Fatal编程技术网

Java 找不到HttpClient间歇页面

Java 找不到HttpClient间歇页面,java,apache-httpclient-4.x,Java,Apache Httpclient 4.x,我使用下面的代码并多次运行该方法,有几次我在GZIP中得到了我所期望的响应,还有几次我得到了完全不同的响应(未找到非GZIP页面)。但是,如果我使用Mozilla或IE多次下载相同的URL,我会始终得到相同的GZIP响应 这是我试图访问的服务器的错误,还是我需要设置任何参数以获得一致的响应 我想下载的网址,你能告诉我吗 public static byte[] dowloadURL(URL urlToDownload) { InputStream iStream = null;

我使用下面的代码并多次运行该方法,有几次我在GZIP中得到了我所期望的响应,还有几次我得到了完全不同的响应(未找到非GZIP页面)。但是,如果我使用Mozilla或IE多次下载相同的URL,我会始终得到相同的GZIP响应

这是我试图访问的服务器的错误,还是我需要设置任何参数以获得一致的响应

我想下载的网址,你能告诉我吗

public static byte[] dowloadURL(URL urlToDownload) {

    InputStream iStream = null;
    byte[] urlBytes = null;

    try {

        //HttpClient httpClient = new HttpClient();
        org.apache.http.client.
        HttpClient httpClient = new DefaultHttpClient();


        HttpGet httpget = new HttpGet(urlToDownload.toString());

        HttpResponse response  = httpClient.execute(httpget);

        iStream = response.getEntity().getContent();

        urlBytes = IOUtils.toByteArray(iStream);
        String responseString = new String(urlBytes);
        System.out.println(" >>> The response  string for " +urlToDownload.toString()+  " is "   +responseString);

    } catch (IOException e) {
        System.err.printf("Failed while reading bytes from %s: %s",
                urlToDownload.toExternalForm(), e.getMessage());
        e.printStackTrace();
        // Perform any other exception handling that's appropriate.
    } finally {
        if (iStream != null) {
            try {
                iStream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    return urlBytes;
}

你能显示stacktrace吗?也许服务器上有一些限制,可以在短时间内阻止来自同一来源的多个请求。您的Java代码可能会足够快地触发油门,而当您在浏览器中手动执行此操作时,速度并没有那么快,因此不会触发油门。