[英]Invalid HTML response when using Java webclient
我在 Spring 中使用 Reactive Webclient,並且在確定為什么從 GET 請求中獲取以下響應格式時遇到了一些困難:
�\jj��T{�8��?�t(O�"V$�@��)���5�����~?��J�t"�� ��EEΕ7�b��,�u�i�=��k���3�ӡ�������m,��ꔁu�T낙*��{�DZ�l�`����{� ��M��+mB)��E{�UtG���ʘJ#ؠ�]j<u�?6�`h���.���𢚾�n��?�ʋ*��#%�w'<L��d�Ly����R�>���$�O�����—o�}�� �����v���{���?����r�;
這是我在下面用於請求的代碼:
return webClient
.get()
.uri(URI.create(uri))
.accept(MediaType.TEXT_HTML, MediaType.APPLICATION_XHTML_XML)
.acceptCharset(StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1)
.header("Accept-Encoding", "gzip, deflate, br")
.retrieve()
.bodyToMono(String.class);
WebClient 設置如下:
HttpClient client = HttpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout)
.followRedirect(true)
.secure()
.responseTimeout(Duration.ofMillis(readTimeoutMillis));
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(client))
.build();
我錯過了什么?
看起來響應是編碼的,可能是 gzip 壓縮的,尤其是你已經向服務器聲明的,你能夠解碼 gzip、deflate 和 br 編碼
Accept-Encoding: gzip,deflate,br
您可以刪除.header("Accept-Encoding", "gzip, deflate, br")
並查看服務器是否願意向您發送純文本響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.