我有这段代码:
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响应。
是什么原因引起的?我怎样才能稳定我的代码?
它偶尔发生,而不是所有网址。