我正在尝试通过代理发送 GET 并且某些站点具有标头: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);
}
我指的错误来自这里。似乎此方法仅支持带有 Content-Encoding 的标头:gzip、deflate 或 identity。