Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Spring boot Spring WebClient执行https调用_Spring Boot_Spring Webflux_Spring Webclient - Fatal编程技术网

Spring boot Spring WebClient执行https调用

Spring boot Spring WebClient执行https调用,spring-boot,spring-webflux,spring-webclient,Spring Boot,Spring Webflux,Spring Webclient,有人知道如何配置WebClient以创建HTTPS端点吗 我的配置如下所示: @Bean @NonNull public WebClient webClient() throws SSLException { final SslContext context = SslContextBuilder.forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE)

有人知道如何配置WebClient以创建HTTPS端点吗

我的配置如下所示:

    @Bean
    @NonNull
    public WebClient webClient() throws SSLException {
        final SslContext context = SslContextBuilder.forClient()
                .trustManager(InsecureTrustManagerFactory.INSTANCE)
                .build();

        final HttpClient httpClient = HttpClient.create().secure(t -> t.sslContext(context));

        return WebClient
                .builder()
                .exchangeStrategies(ExchangeStrategies.builder()
                        .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(16 * 1024 * 1024))
                        .build())
                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .build();
    }
下面是访问HTTPS端点的方法

    @Nullable
    public AccessToken getAccessToken() {
        return webClient
                .post()
                .uri(uriBuilder -> uriBuilder.path(authUrl)
                        .queryParam("username", username)
                        .queryParam("password", password)
                        .queryParam("client_id", clientId)
                        .queryParam("client_secret", clientSecret)
                        .queryParam("grant_type", "password")
                        .build())
                .header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
                .exchange()
                .flatMap(response -> {
                    //Error handling
                    if (response.statusCode().isError()) {
                        logger.error("error occured while authentication: {}", response.statusCode());
                        return response.createException().flatMap(Mono::error);
                    }
                    return response.bodyToMono(AccessToken.class);
                })
                .subscribeOn(Schedulers.elastic())
                .block();
    }
这是我的回答,不幸的是,我不允许显示所有的细节,因为有安全的数据。 所以我检查了所有内容,比如URL、参数,看起来都很好。同样,如果对restTemaple执行相同的操作,它也会起作用

Caused by: java.net.UnknownHostException: https:
    at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:798)
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ Request to POST https:/<here goes secured endpoint with query parameters>
原因:java.net.UnknownHostException:https:
位于java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:798)
抑制:reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
在以下站点发现错误:
|_检查站⇢ 请求发布https:/

也许可以help@AmirSchnell正如您可能看到的,这已经像url上的示例中那样进行了配置,但它没有帮助您确定url是正确的吗
UnknownHostException
是由java无法从提供的主机名解析IP地址引起的。本质上DNS查找失败。问题是您无法共享错误的部分:主机名。这让我很难帮忙,也许我能help@AmirSchnell正如您可能看到的,这已经像url上的示例中那样进行了配置,但它没有帮助您确定url是正确的吗
UnknownHostException
是由java无法从提供的主机名解析IP地址引起的。本质上DNS查找失败。问题是您无法共享错误的部分:主机名。这使帮助变得很困难。