Uso de RestTemplate
Estou tentando usarRestTemplate
a fim de fazer umaPUT
. Por alguma razão eu não consigo reproduzirPUT
Eu criei usandocurl
que passa sem problemas.
Aqui está o meucurl
chamada que sucede e retorna 200:
curl https://www.exampe.com \
-X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <bearer-token>" \
-v \
-d '{"json":"object"}'
E aqui está o código Java que tentou replicar issocurl
ligar. Este código no meu caso vai jogarHttpClientErrorException
com status = 406:
boolean result = false;
String url = "https://www.example.com";
String json = "{\"json\":\"object\"}";
RestTemplate rest = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
headers.add("Authorization", String.format("Bearer %s", authToken));
HttpEntity<String> requestEntity = new HttpEntity<String>(json, headers);
ResponseEntity<String> responseEntity =
rest.exchange(url, HttpMethod.PUT, requestEntity, String.class);
HttpStatus status = responseEntity.getStatusCode();
Qual a diferença entre esses pedidos? Como faço para convergir a versão do Java para ocurl
versão?