0

I have a Postman POST request which looks like the following:

enter image description here

The code I'm using to map the above into code using Jersey's WebResource is the following, but it's not working:

Client authKeyClient = Client.create();
WebResource webResource = authKeyClient.resource("https://ims-na1-stg1.company.com/token/v1");
String input = "{\"grant_type\":\"authorization_code\",\"client_id\":\"orders\",\"client_secret\":\"0af3b233-f1ca-41da-a0fa-61c08d15cadc\",\"code\":\"eyJhbGciOiJSUzI1NiIsIng1dSI6Imltc19uYTEtc\"}";
currentEnv.getImsSecret()).header("code", currentEnv.imsCode).get(String.class);
String response = webResource.post(String.class, input);

I end up getting a 400 Bad Request. What am I doing wrong ?

Ahmad
  • 12,886
  • 30
  • 93
  • 146

1 Answers1

0

Try adding Content-Type. I would also suggest to send request in more structured way to avoid mistype mistakes:

MultivaluedMap formData = new MultivaluedMapImpl();
formData.add("name1", "val1");
formData.add("name2", "val2");
ClientResponse response = webResource
    .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
    .post(ClientResponse.class, formData);

Similar discussion: Using the Jersey client to do a POST operation

Community
  • 1
  • 1
Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114