最佳答案
我有一个 webservice,它接受一个带有 XML 的 POST 方法。它工作良好,然后在某些随机场合,它未能通信到服务器抛出 IOException 与消息 The target server failed to respond
。后续调用工作正常。
大多数情况下,当我打了一些电话,然后让我的应用程序空闲大约10-15分钟。之后进行的第一个调用返回这个错误。
我尝试了很多方法。
我将重试处理程序设置为
HttpRequestRetryHandler retryHandler = new HttpRequestRetryHandler() {
public boolean retryRequest(IOException e, int retryCount, HttpContext httpCtx) {
if (retryCount >= 3){
Logger.warn(CALLER, "Maximum tries reached, exception would be thrown to outer block");
return false;
}
if (e instanceof org.apache.http.NoHttpResponseException){
Logger.warn(CALLER, "No response from server on "+retryCount+" call");
return true;
}
return false;
}
};
httpPost.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
但是这个重试从来没有被调用过。(是的,我使用的是正确的 instanceof 子句)当调试这个类的时候从来没有被调用过。
我甚至尝试设置 HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), false);
,但没有用。有人可以建议我现在可以做什么?
很重要 除了搞清楚为什么我会得到这个异常之外,我还有一个重要的问题是为什么重试处理程序不在这里工作?