将“Content-Encoding”头添加到请求后出现400错误
问题描述:
我试图通过向请求添加“Content-Encoding”头来执行POST调用。这里是我的代码将“Content-Encoding”头添加到请求后出现400错误
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头
回应说: “内容编码”标题丢失。 任何人都可以在这里帮助我,并指出我正确的做法吗?
答
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();
以不同的方式解决了这个问题。 –