String Stringifiedjson = new Gson().toJson(user);
Log.d("SpringAndroid", Stringifiedjson);
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Collections.singletonList(new
MediaType("application", "json")));
HttpEntity <? > requestEntity = new HttpEntity <Object>
(Stringifiedjson, requestHeaders);
GsonHttpMessageConverter messageConverter = new GsonHttpMessageConverter();
List < HttpMessageConverter <? >> messageConverters =
new ArrayList < HttpMessageConverter <? >>();
messageConverters.add(messageConverter);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setMessageConverters(messageConverters);
try {
ResponseEntity<String> responseEntity = restTemplate.
exchange(url, HttpMethod.POST, requestEntity, String.class);
}
我得到一個400錯誤請求400錯誤的請求,但是當我在我的小提琴手發送Stringifiedjson
。我收到一個有效的response
。現在如何使用RestTemplate發佈GSON對象HTTPClientErrorException:使用Spring REST模板