Выполнение простого вызова «delivery_quotes» API Postmates для тестирования, которое не возвращает подходящего HttpMessageConverter для типа запроса - PullRequest
0 голосов
/ 18 марта 2019

Использование Spring, простой вызов API delivery_quotes и получение ошибки:

org.springframework.web.client.RestClientException: Невозможно записать запрос: не найден подходящий HttpMessageConverter для типа запроса[MyEntity] и тип контента [application / x-www-form-urlencoded]

 String resourceUrl = "https://api.postmates.com/v1/customers/cus_XXXXXXX/delivery_quotes";
 RestTemplate restTemplate = new RestTemplate();

 HttpHeaders headers = new HttpHeaders();
 headers.set("Authorization","Basic ".concat(Base64.getEncoder().encodeToString("XXXXX-XXX-XXX-XX-XXX".getBytes())));
 headers.set("Content-Type", "application/x-www-form-urlencoded");

 MyEntity request = new MyEntity();
 request.setDropoff_address("140, San Francisco, CA");
 request.setPickup_address("101 Market St, San Francisco, CA");

 HttpEntity<MyEntity> httpEntity = new HttpEntity<MyEntity>(request,headers);
 ResponseEntity<Object> entity = restTemplate.exchange(resourceUrl,HttpMethod.POST,httpEntity,Object.class);
 Object body = entity.getBody()

Ниже приведено исключение, которое я получаю:

Error :: org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [MyEntity] and content type [application/x-www-form-urlencoded]
 Error :: Could not write request: no suitable HttpMessageConverter found for request type [MyEntity] and content type [application/x-www-form-urlencoded]
org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [MyEntity] and content type [application/x-www-form-urlencoded]
    at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:933)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:685)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:644)
    at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:430)

Любая помощь будетБуду очень признателен.

...