Elad Benda Elad Benda - 1 month ago 11x
HTTP Question

how to make javax.ws post request similar to postman request?

I try to send an http post request with postman and it works
(it works using

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
.header("Authorization", commonClient.authorizedRequestBuilder())
.post(Entity.entity(formData, MediaType.APPLICATION_JSON))

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


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");