【问题标题】:How to add parameter to HTTP header using Apache HttpClient如何使用 Apache HttpClient 向 HTTP 标头添加参数
【发布时间】:2015-02-17 09:20:15
【问题描述】:

我正在尝试使用 HttpClient 将“Accept-Encoding”参数作为“gzip,deflate”添加到我的 HTTP 标头中。代码如下。但是,我收到以下响应错误并且无法添加标头参数。响应不包含添加的标头字段

String url = "http://192.168.1.25:8380/ABCDService?wsdl";
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
post.addHeader( "Accept-Encoding", "gzip,deflate" );
HttpResponse response = client.execute(post);

错误:内部服务器错误

【问题讨论】:

标签: java apache http http-headers apache-httpclient-4.x


【解决方案1】:

看起来像是服务器配置问题。 你启用压缩服务器端了吗?

如果您使用 jax-rs,如果您设置了标头,则可以使用带有压缩响应的 reasteasy 回复。

在其他框架中,您可能必须自己设置。使用 @gzip 或实现 WriterInterceptor

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 2019-09-12
    • 2017-12-30
    相关资源
    最近更新 更多