【发布时间】:2020-09-02 09:22:04
【问题描述】:
我正在尝试从 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() 是 阻塞,线程 reactor-http-nio-3 不支持
这里出了什么问题?我对reactive-programming 很陌生,谷歌搜索问题表明为什么需要block?
提前谢谢你。
【问题讨论】:
标签: java spring-boot http resttemplate spring-webclient