Get native REST service error in Unirest Get native REST service error in Unirest json json

Get native REST service error in Unirest


Since you cannot rely on the returned content type, the workaround is to treat the response as String:

  HttpResponse<String> response = Unirest      .post(url)      .header(HEADER_CONTENT_TYPE, HEADER_VALUE_APPLICATON_JSON)      .body(payload)      .asString();

This way you will have access to the return status code. Unirest will not try to parse the result to JSON, so you need to do it yourself (if the status code indicates success).