Hi I am using Glassfish jersey-client to get oauth-Token from REST URL. I am able to get the token via postman client & CURL,please find the below image for reference,
$ curl 'https://sample.com/oauth2/token' -X POST -d'g
rant_type=samples&id=2ZwqWBdksfjkads6Q8yNW3s58LNeOMucJeb&s
ecret=dkfflJTZOqA1GCEH&scope=GROUP'
But unable to achieve it via code,
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.2</version>
</dependency>
I am using following code to get the token
Form form = new Form();
form.param("grant_type", "samples");
form.param("id", "2ZwqWBdksfjkads6Q8yNW3s58LNeOMucJeb");
form.param("secret", "HGoslJTZOqA1GCEH");
form.param("scope", "dkfflJTZOqA1GCEH");
JerseyClientBuilder jerseyClientBuilder = new JerseyClientBuilder()
.register(new LoggingFilter());
JerseyWebTarget jerseyWebTarget = jerseyClientBuilder.build().target(hostname);
response = jerseyWebTarget.request().accept(MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
Keep on getting StatusCode=406(Not acceptable) as a response. Shall i passing the URL parameters properly?
I would highly appreciate if someone give me a hint to resolve this issue.