Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.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 webclient引发块不受支持异常_Java_Spring Boot_Http_Resttemplate_Spring Webclient - Fatal编程技术网

Java Spring webclient引发块不受支持异常

Java Spring webclient引发块不受支持异常,java,spring-boot,http,resttemplate,spring-webclient,Java,Spring Boot,Http,Resttemplate,Spring Webclient,我正在尝试从spring boot进行HTTP调用。在post man中调用工作正常,下面是调用的curl版本 curl --location --request POST 'https://sampletest.com:8811/rest/oauth/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --header 'Accept: application/json' \ --data-urlencod

我正在尝试从
spring boot
进行HTTP调用。在post man中调用工作正常,下面是调用的
curl
版本

curl --location --request POST 'https://sampletest.com:8811/rest/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Accept: application/json' \
--data-urlencode 'client_id=126763****ghsei99****' \
--data-urlencode 'client_secret=126763****ghsei99****' \
--data-urlencode 'param1=pppp' \
--data-urlencode 'param2=pppp'
但我正试图使用
WebClient
拨打相同的电话

WebClient webClient = WebClient.builder().baseUrl("https://sampletest.com:8811")
                    .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE).build();

            MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
            formData.add("client_id","126763****ghsei99****");
            formData.add("client_secret", "126763****ghsei99****");
            formData.add("param1","pppp");
            formData.add("param2","pppp");

            AuthenticationResponseBean authenticationResponseBean = webClient.post().uri("/rest/oauth/token").body(BodyInserters.fromFormData(formData))
                    .retrieve().bodyToFlux(AuthenticationResponseBean.class).blockLast();
WebClient-WebClient=WebClient.builder().baseUrl(“https://sampletest.com:8811")
.defaultHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_FORM_URLENCODED_VALUE).build();
MultiValueMap formData=新链接的MultiValueMap();
添加(“客户id”,“126763****ghsei99****”;
formData.添加(“客户机密”、“126763****ghsei99****”;
formData.add(“参数1”、“pppp”);
formData.add(“param2”、“pppp”);
AuthenticationResponseBean AuthenticationResponseBean=webClient.post().uri(“/rest/oauth/token”).body(BodyInserters.fromFormData(formData))
.retrieve().bodyToFlux(AuthenticationResponseBean.class).blockLast();
但是,应用程序正在抛出异常

java.lang.IllegalStateException:block()/blockFirst()/blockLast()是 阻塞,这在线程reactor-http-nio-3中不受支持

这里出了什么问题?我对
反应式编程非常陌生
,谷歌搜索问题表明为什么需要


提前谢谢。

据我所知,阻塞实际上会阻塞线程。从:

  • “无限期阻塞,直到上游发出最后一个值或 完成”
因此,如果不需要阻塞,或者不需要等待最后一个元素,就不需要它。因此,根据您的需要,只需订阅即可