SocketException:执行POST请求时重置连接

时间:2019-05-03 04:21:22

标签: sockets post

我正在向端点发出POST请求。我正在使用Spring restTemplate。

我很少(100分之一)得到SocketException,但是我想避免这种情况。

final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity<String> entity;
entity = new HttpEntity<>(inputPayload[0], headers);
final RestTemplate restTemplate = new RestTemplate();
  return retryTemplate.execute(new RetryCallback<String, Exception> 
                       () {
       @Override
       public String doWithRetry(RetryContext context) throws 
       Exception {
         return restTemplate.exchange(url, httpMethod, entity, 
         String.class).getBody();
     }
});

异常堆栈跟踪:

 Caused by: org.springframework.web.client.ResourceAccessException: 
 I/O error on POST request for "": Connection reset; nested 
 exception is java.net.SocketException: Connection reset
 at 
 Caused by: java.net.SocketException: Connection reset
 at java.net.SocketInputStream.read(SocketInputStream.java:210)
 at java.net.SocketInputStream.read(SocketInputStream.java:141)
 at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
 at sun.security.ssl.InputRecord.read(InputRecord.java:503)

好像在我的(客户端)端,关闭连接后,我仍在从SocketInputStream读取吗?如何完全解决?

0 个答案:

没有答案