gpt4 book ai didi

java - 为什么 apache java http 库不处理内容编码为 : none? 的站点

转载 作者:行者123 更新时间:2023-11-29 07:05:22 25 4
gpt4 key购买 nike

我正在尝试通过代理发送 GET,而某些站点具有 header :Content-Encoding: none,这会导致 Apache 抛出异常。我想知道这是否是预期的行为,以及我是否应该将其视为错误:

Caused by: org.apache.http.HttpException: Unsupported Content-Coding: none
at org.apache.http.client.protocol.ResponseContentEncoding.process(ResponseContentEncoding.java:98)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:139)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:199)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
... 10 more

我的代码:

public CloseableHttpResponse getViaProxy(String url, String ip, int port, String username,
String password) {
CloseableHttpClient httpClient;
if (username == null) {
httpClient = HttpClients.custom()
.setSSLSocketFactory(getCustomSslConnectionSocketFactory())
.build();
} else {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(ip, port),
new UsernamePasswordCredentials(username, password));
httpClient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.setSSLSocketFactory(getCustomSslConnectionSocketFactory())
.build();
}

RequestConfig config = RequestConfig.custom()
.setProxy(new HttpHost(ip, port))
.build();
HttpGet httpGet = new HttpGet(url);
httpGet.setConfig(config);

return httpClient.execute(httpGet);
}

我指的错误来自这里。似乎此方法仅支持具有内容编码的 header :gzip、deflate 或 identity。

http://hc.apache.org/httpcomponents-client-ga/httpclient/xref/org/apache/http/client/protocol/ResponseContentEncoding.html

最佳答案

HTTP 协议(protocol)规范将gzipcompressdeflateidentity 定义为有效的内容编码方案。应该使用 identity 来表示不需要进行内容转换。

关于java - 为什么 apache java http 库不处理内容编码为 : none? 的站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20429722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com