As seen in the image above, I am sending grant_type=client_credentials as post body. The equivalent curl command is
curl --location --request POST 'https://localhost:8080/token'
--header 'Authorization: Basic **************************************'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'grant_type=client_credentials'
I am able to send grant_type=client_credentials as query parameter and get a successful response. But we are asked not to use as query param because of company policy and asked to send it in body.
The code which I came up with is
public Message<Map<String, String>> getTokenGenRequest() {
setHeaderMapper(new String[] { TransferConstants.AUTHORIZATION, TransferConstants.CONTENT_TYPE });
Map<String, String> requestMap = new HashMap<String, String>();
requestMap.put("grant_type", "client_credentials");
return MessageBuilder.withPayload(requestMap)
.setHeader(TransferConstants.AUTHORIZATION, getAuthCredentials())
.setHeader(TransferConstants.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).build();
}
private void setHeaderMapper(String[] headerNames) {
headerMapper.setOutboundHeaderNames(headerNames);
}
However the request goes out Writing [{grant_type=[client_credentials]}] as "application/x-www-form-urlencoded" due to which I am not getting any response.Can somebody tell me what is wrong with the code?