我正在尝试从spring-boot
进行HTTP调用。该呼叫在邮递员中正常运行,下面是该呼叫的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();
但是,应用程序抛出异常,
java.lang.IllegalStateException:block()/ blockFirst()/ blockLast()是阻塞,这在线程反应堆中不支持-http-nio-3
这里出了什么问题?我对reactive-programming
非常陌生,而Google搜索问题表明为什么需要block
?
先谢谢您。