-2

I try to send an http post request with postman and it works (it works using curl as well)

I get a positive response

enter image description here

I try to do the same request in code using

import javax.ws.rs.client.WebTarget;



        Map<String, String> formData = new HashMap();
        formData.put("update_type", "config");
        formData.put("role", role);
        formData.put("name", configNameCamelCase);
        formData.put("version", version);
        formData.put("work_env", env);
        formData.put("project", "waze-prod");
        formData.put("provider", "gce");


        try {
            String a = commonClient.webTarget
                    .path("/tasks/update_version")
                    .request()
                    .header("Authorization", commonClient.authorizedRequestBuilder())
                    .accept(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
                    .post(Entity.entity(formData, MediaType.APPLICATION_JSON))
                    .readEntity(String.class);
}

How should i change my code to make it identical to the postman request

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

1

Use Form and just add parameters with Form#param(key, value). Then use .post(Entity.form(form)).

Form form = new Form()
  .param("one", "two")
  .param("three", "four");

...post(Entity.form(form));
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720