Unirest is not returning expected result on PUT request [Java]

360 views Asked by At

I am trying using an end point for updating a record, now that is working fine for postman, but it is not working for Unirest, as I have used everything. My code is like this:

    public static void updateTrialLength()throws IOException {
        String baseURL = whatever_URL_is;
        String path = "company/761";
        String url = baseURL + path;
        String token = getToken(username, password);
        Map<String, String> headers = new HashMap<>();
        headers.put("x-access-token", token);
        headers.put("accept", "application/json");
        String str = "{\"isTrial\":"+1+"}";
        JSONObject json = new JSONObject(str);
        try {
            HttpResponse<JsonNode> response = Unirest.put(url).header("x-access-token", token).
                    body(json).asJson();
            System.out.println(response.getBody());
        } catch (UnirestException e) {
            throw new IOException(e);
        }

    }

Now upon using this command, I have to change the value i.e. 'isTrial' is 0, and I have to update it to 1. I have used everything, its working at all. PostMan Result can be viewed from here. Its quiet frustrating now.

0

There are 0 answers