Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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调用url返回404,而通过chrome浏览器则可以正常工作_Java_Url_Jersey_Http Status Code 404 - Fatal编程技术网

通过java调用url返回404,而通过chrome浏览器则可以正常工作

通过java调用url返回404,而通过chrome浏览器则可以正常工作,java,url,jersey,http-status-code-404,Java,Url,Jersey,Http Status Code 404,我有以下代码: private CompleteRoutingResponseWrapper sendRoutingRequestString(String routingRequestUrl) { routingRequestUrl = urlUtils.getHttpUrl(routingRequestUrl); CompleteRoutingResponseWrapper answer = new CompleteRoutingResponseWrapper();

我有以下代码:

private CompleteRoutingResponseWrapper sendRoutingRequestString(String routingRequestUrl) {
    routingRequestUrl = urlUtils.getHttpUrl(routingRequestUrl);

    CompleteRoutingResponseWrapper answer = new CompleteRoutingResponseWrapper();
    CloseableHttpClient client = HttpClientBuilder.create().build();
    CloseableHttpResponse response = null;
    try {

        Stopwatch stopWatch = Stopwatch.createStarted();
        response = client.execute(new HttpGet(routingRequestUrl));
        stopWatch.stop();

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            answer.errorMsg = handleError(routingRequestUrl, response, statusCode);
            answer.completeRoutingResponse = new com.waze.routing.automation.dataModel.serverResponse.dto
                    .CompleteRoutingResponse();
        } else {
            String bodyAsString = EntityUtils.toString(response.getEntity());
            answer.completeRoutingResponse = handleSuccess(bodyAsString);
            answer.latency = stopWatch.elapsed(TimeUnit.MILLISECONDS);
            handleErrorInBody(routingRequestUrl, answer, bodyAsString);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return answer;
}
我用数百个URL调用这个方法

对于他们中的一些人,我偶尔得到404

然而,当我想从浏览器本身调用这些URL时,我得到了OK响应

这是什么原因造成的?如何稳定我的代码


这种情况偶尔发生,并非所有URL都会发生。

他们的服务器上是否存在基于用户代理的过滤?@Sandeep no,因为这种情况偶尔发生,并非所有URL都会发生。还有别的想法吗?