通过java调用网址返回404,而通过Chrome浏览器工作正常

时间:2015-05-09 22:09:06

标签: java url jersey http-status-code-404

我有这段代码:

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;
}

我用数百个网址称这个方法。

对于其中一些我偶尔会得到404。

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

是什么原因引起的?我怎样才能稳定我的代码?

它偶尔发生,而不是所有网址。

0 个答案:

没有答案