List<NameValuePair> postParameters = new ArrayList<>();
HttpPost httpPost = new HttpPost("http://example.com");
postParameters.add(new BasicNameValuePair("grant_type", "client_credentials"));
httpPost.setEntity(new UrlEncodedFormEntity(postParameters, "UTF-8"));
httpPost.setHeader("HttpHeaders.AUTHORIZATION", "Basic "+base64encoded);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
tokenApiResponse = this.httpClient.execute(httpPost);
LOGGER.log(Level.INFO,"Token response:{0}",tokenApiResponse.getStatusLine().getStatusCode());
Iam getting 401 unauthorized as status code.
Can someone please review the way I’m setting grant_type into HttpPost request.
I’m being little skeptical there.
In linux, below is the piece which I’ve to achieve in java –
curl --location 'https://dev1.erf.us-phoenix-1.ocs.oc-test.com/ords/erfp/oauth/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--header 'Authorization: ••••••'
--data-urlencode 'grant_type=client_credentials'