My code in MVC API C# this:
[System.Web.Http.HttpPost]
[System.Web.Http.Route("api/ServiceV1/Test")]
public IHttpActionResult Test()
{
return BadRequest("Catch this message in Android application");
}
Result in PostMan
{
"Message": "Catch this message in Android application"
}
I catch this error message on android application. I used okhttp3.
String MIME_JSON = "application/json";
Gson gson = new Gson();
RequestBody body = RequestBody.create(MediaType.parse(MIME_JSON), gson.toJson(object));
Request request = new Request.Builder()
.url(baseUrl + route)
.post(body)
.build();
okHttpClient.newCall(request).execute();
How do to catch this message on the Android application?