entity对于http方法GET必须为空



我正在尝试使用一个暴露于支付提供商的外部api。我使用Jersey和javax.ws.rs作为请求,因为我可以轻松地发送带有Digest的认证。

但在请求,用载荷,泽西岛返回

> IllegalStateException. Entity must be null for http method GET
CashTransactionResponse responseData = null;
//We connect to intouch server
String requestUrl = rootUrlTouchPay + agency.getAgencyCode() + "/" + IntouchMethodApis.TRANSACTION + "?loginAgent=" + agency.getLogin() + "&passwordAgent=" + agency.getPassword();
ClientConfig clientConfig = new ClientConfig();
//Open Digest authentication
HttpAuthenticationFeature feature = HttpAuthenticationFeature.digest(BASIC_LOGIN, BASIC_PWD);
clientConfig.register(feature);
clientConfig.register(JacksonFeature.class);
//Create new rest client
Client client = ClientBuilder.newClient(clientConfig);
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
//Set the url
WebTarget webTarget = client.target(requestUrl);
Invocation.Builder invocationBuilder = webTarget.request(javax.ws.rs.core.MediaType.APPLICATION_JSON);
logger.info("Initialisation of cashout service successful for cash");
// create request
Gson gson = new Gson();
String transactionString = gson.toJson(cashRequest);
Response response = null;
// start the response
if (cashRequest.getServiceCode().contains(TelecomEnum.WAVE.name().toUpperCase())) {
response = invocationBuilder.method("GET", Entity.entity(transactionString, javax.ws.rs.core.MediaType.APPLICATION_JSON));
} else {
response = invocationBuilder.put(Entity.entity(transactionString, javax.ws.rs.core.MediaType.APPLICATION_JSON));
}

请告诉我如何发送我的GET请求与正文?

感谢

我认为问题出在

Client Client = ClientBuilder.newClient(clientConfig);clientConfig.property (ClientProperties。SUPPRESS_HTTP_COMPLIANCE_VALIDATION,真);

client复制了clientConfig的值,clientConfig的任何设置对client没有任何影响。

切换行或在client上设置ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION属性。

使用invocationBuilder.post(entity)代替invocationBuilder.method("GET", ...),如下所述。这将允许您将事务字符串POST到端点。

相关内容

最新更新