gpt4 book ai didi

java - 添加 "Content-Encoding" header 到请求后出现 400 错误

转载 作者:行者123 更新时间:2023-12-02 12:28:58 26 4
gpt4 key购买 nike

我正在尝试通过向请求添加“Content-Encoding” header 来执行 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 header

响应称“Content-Encoding” header 丢失。谁能在这里帮助我,并指出我正确的做法?

最佳答案

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();

关于java - 添加 "Content-Encoding" header 到请求后出现 400 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45376594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com