Spring boot Spring引导-调用另一个需要证书的web服务

Spring boot Spring引导-调用另一个需要证书的web服务,spring-boot,Spring Boot,我有一个SpringBootREST服务,它将调用另一个web服务(用.NET编写),但它需要安装web服务的服务器的公共证书 我得到以下错误: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://domain.sample.com/api/message.asmx": sun.security.validator.ValidatorException: PK

我有一个SpringBootREST服务,它将调用另一个web服务(用.NET编写),但它需要安装web服务的服务器的公共证书

我得到以下错误:

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://domain.sample.com/api/message.asmx": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Process finished with exit code -1
不确定是否可以使用RestTemplate调用.asmx web服务,但这是我的代码:

RestTemplate restTemplate = new RestTemplate();

HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.TEXT_XML);

HttpEntity<String> entity = new HttpEntity<>(rawDeviceMessage, httpHeaders);

ResponseEntity<String> resultEntity = restTemplate.postForEntity("https://domain.sample.com/api/message.asmx", entity, String.class);
RestTemplate RestTemplate=new RestTemplate();
HttpHeaders HttpHeaders=新的HttpHeaders();
httpHeaders.setContentType(MediaType.TEXT_XML);
HttpEntity=新的HttpEntity(rawDeviceMessage,HttpHeader);
ResponseEntity resultEntity=restTemplate.postForEntity(“https://domain.sample.com/api/message.asmx,实体,字符串.class);

正如@Mustafa在上面的评论部分所提到的,以下是重复的,问题得到了解决


您是否已将.Net服务器的公钥添加到服务器的信任库中?如果您的服务不使用受信任的证书,您需要手动将其添加到您的信任库中。可能是Hi@Mustafa的副本,谢谢。我会检查一下,然后再给你回复。