我必須在發佈請求的主體中傳遞鍵值對。但是,當我運行我的代碼時,我得到的錯誤爲「無法寫請求:沒有找到合適的HttpMessageConverter請求類型[org.springframework.util.LinkedMultiValueMap]和內容類型[文本/純]」如何在java中使用resttemplate傳遞鍵值對
我的代碼是如下:
MultiValueMap<String, String> bodyMap = new LinkedMultiValueMap<String, String>();
bodyMap.add(GiftangoRewardProviderConstants.GIFTANGO_SOLUTION_ID, giftango_solution_id);
bodyMap.add(GiftangoRewardProviderConstants.SECURITY_TOKEN, security_token);
bodyMap.add(GiftangoRewardProviderConstants.REQUEST_TYPE, request_type);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(bodyMap, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> model = restTemplate.exchange(giftango_us_url, HttpMethod.POST, request, String.class);
String response = model.getBody();
並確保resttemplate配置了FormHttpMessageConverter如果你打算使用APPLICATION_FORM_URLENCODED too- – chrismarx 2015-11-24 16:02:47