Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在spring rest模板客户端中找不到请求目标的有效证书路径_Java_Spring_Rest_Security_Ssl - Fatal编程技术网

Java 在spring rest模板客户端中找不到请求目标的有效证书路径

Java 在spring rest模板客户端中找不到请求目标的有效证书路径,java,spring,rest,security,ssl,Java,Spring,Rest,Security,Ssl,我越来越 线程“main”org.springframework.web.client.ResourceAccessException中的异常 对于以下程序: private static String url = "https://localhost:8080/ipn"; public static void main( String[] args ) { HttpHeaders headers = new HttpHeaders(); headers.add

我越来越

线程“main”org.springframework.web.client.ResourceAccessException中的异常

对于以下程序:

private static String       url    = "https://localhost:8080/ipn";
public static void main( String[] args )
{
    HttpHeaders headers = new HttpHeaders();
    headers.add( "Accept", "application/json" );
    headers.setContentType( MediaType.APPLICATION_JSON );
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient();

    RestTemplate restTemplate = new RestTemplate( requestFactory );
    requestChange( headers, restTemplate );
}

private static void requestChange( HttpHeaders inHeaders, RestTemplate inRestTemplate )
{
    Map<String, String> params = new HashMap<String, String>();

    params.put( "PresentmentCurrencyCode", "INR" );
    params.put( "SettlementCurrencyCode", "INR" );
    HttpEntity<String> request = new HttpEntity<String>( inHeaders );
    ResponseEntity<String> response = inRestTemplate.exchange( url, HttpMethod.GET, request, String.class, params );
    System.out.println( response.toString() );
}

localhost拼写可能存在打字错误

尝试按以下方式进行更改:


私有静态字符串url=“”

您的客户端似乎不信任您正在调用的资源。您必须导入目标资源的公钥,因为您似乎没有在任何地方设置SSL上下文,因此您的应用程序不知道如何验证您建立的https连接

您需要在初始化httpClient时进行设置,例如:

socketFactory = new SSLConnectionSocketFactory(sslContext);
httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
socketFactory = new SSLConnectionSocketFactory(sslContext);
httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();