【问题标题】:400 error after adding "Content-Encoding" header to request将“Content-Encoding”标头添加到请求后出现 400 错误
【发布时间】:2017-07-28 14:55:15
【问题描述】:

我正在尝试通过在请求中添加“Content-Encoding”标头来进行 POST 调用。这是我的代码

Invocation.Builder builder =  
webTarget.request(MediaType.APPLICATION_XML).header("Content-Encoding", 
"xml").accept(MediaType.TEXT_PLAIN);
String xmlRequest= 
buildMerchantPreferencesRequest(accountNumber,emailID,thresholdValue);
response = header.post(Entity.xml(xmlRequest.toString()));

String value = response.readEntity(String.class);
Thread.sleep(5000);
System.out.println("Service STATUS : "+response.getStatus());
System.out.println("Response message : "+value);

返回响应如下: 状态:400 响应消息:请求服务 PreferencesLifecycle 版本 1.0- 211.0-35789706 缺少 Content-Encoding 标头

响应说“内容编码”标头丢失。 任何人都可以在这里帮助我,并指出正确的方法吗?

【问题讨论】:

  • 通过不同的方式解决了这个问题。

标签: java http-headers httpwebrequest webclient content-encoding


【解决方案1】:
Response response;
        String xmlRequest= buildMerchantNBPreferencesRequest(accountNumber,emailID,thresholdValue);
        Variant variant = new Variant(MediaType.APPLICATION_XML_TYPE, null, null, "XML");        
        Invocation.Builder builder = merchantPreferencesClient.request().header("Content-Encoding", "XML").property("Content-Encoding", "XML");
        Invocation invocation =    builder.header("Content-Encoding", "XML").buildPost(Entity.entity(xmlRequest, variant));
        response = invocation.invoke();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-20
    • 2021-06-02
    • 1970-01-01
    • 2018-03-09
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    相关资源
    最近更新 更多