-2
Hi, I’m trying to make a POST type request with Bearer token for an endpoint. When I perform this request by the postamn it returns normally, but when it is performed by the method I created using java’s Resttemplate api, it gives the error "401 Unauthorized". Follow the code below:
public <T> T sendRequestWithBody(String urlRequest, String jsonValue){
HttpHeaders header = new HttpHeaders();
header.set("Autorization", "Bearer ".concat(getToken()));
JSONObject jsonObject = new JSONObject();
jsonObject.put("query", jsonValue);
RestTemplate restTemplate = new RestTemplate();
HttpEntity<?> request = new HttpEntity<>(jsonObject.toString(), header);
ParameterizedTypeReference<T> typeRef = new ParameterizedTypeReference<T>() {
};
ResponseEntity<T> response = restTemplate.exchange(urlRequest, HttpMethod.POST, request, typeRef);
return response.getBody();
}
Could someone help? Note: I made a method very similar to this to pick up the token, and it generates normally
Hello. It worked that way!
– rlp master