I already looked at How to add headers to a RESTful call using the Jersey client APIs , however this is for Jersey 1.x.
How to set a header value (e.g. authorization token) in Jersey 2.21?
Here is the code I'm using:
public static String POST(final String url, final HashMap<String, String> params) { ClientConfig config = new ClientConfig(); Client client = ClientBuilder.newClient(config); WebTarget target = client.target(url); String data = new Gson().toJson(params); Entity json = Entity.entity(data, MediaType.APPLICATION_JSON_TYPE); Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON_TYPE); return builder.post(json, String.class); }
Joshua kissoon
source share