サービスを使用するためにrestTemplateを使用しています。RestTemplateがAPPLICATION_FORM_URLENCODEDおよびRequest Pojoで機能しない
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity request = new HttpEntity(countryRequest, headers);
CountryResponse response = restTemplate.postForObject(countryURL, request, CountryResponse.class);
countryRequest
は単なる文字列フィールドcode
とPOJOの目的です。 restTemplate
はjackson2HttpMessageConverter
とFormHttpMessageConverter
がmessageConverters
にあります。
私は次の例外取得しています:
org.springframework.web.client.RestClientException:
Could not write request: no suitable HttpMessageConverter found for request type [CountryRequest] and content type [application/x-www-form-urlencoded]
をしかし、私はMultiValueMap
の代わりCountryRequest
を使用している場合、私は200応答を得た:
MultiValueMap<String, String> map= new LinkedMultiValueMap<>();
map.add(code, "usa");
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity(map, headers);
はここMultiValueMap
アプローチを交換する方法はあります?