Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 400添加“后出现错误”;内容编码“;要请求的标题_Java_Http Headers_Httpwebrequest_Webclient_Content Encoding - Fatal编程技术网

Java 400添加“后出现错误”;内容编码“;要请求的标题

Java 400添加“后出现错误”;内容编码“;要请求的标题,java,http-headers,httpwebrequest,webclient,content-encoding,Java,Http Headers,Httpwebrequest,Webclient,Content Encoding,我试图通过在请求中添加“Content Encoding”头来进行POST调用。这是我的密码 Invocation.Builder builder = webTarget.request(MediaType.APPLICATION_XML).header("Content-Encoding", "xml").accept(MediaType.TEXT_PLAIN); String xmlRequest= buildMerchantPreferencesRequest(accountNum

我试图通过在请求中添加“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 响应消息:请求服务首选项生命周期1.0版- 211.0-35789706缺少内容编码标头

响应表示缺少“内容编码”标题。
有谁能帮我一下,给我指出正确的方法吗?

用另一种方法解决了这个问题。
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();