I'm developing an Android app (Client). The server works with C#. When I make some request specifically some Posts, I'm getting an error message on bad request such as 'HTTP/1.1 404 Not Found' which is okay when the item I searched for is incorrect. But on bad request the server sends me also a message body in JSON, something like this:
{
"responseMessage":"The item you searched not found"
}
Is there a way to get this message (and NOT the bad request message 'HTTP/1.1 404 Not Found') and show it as a response of bad request? The back end works fine, I check it on Postman. My code of Post request is this:
Json := '{ '+
' "code":"'+str+'",'+
' "userid":'+userid+''+
' } ';
JsonToSend := TStringStream.Create(Json, TEncoding.UTF8);
try
IdHTTP1.Request.ContentType := 'application/json';
IdHTTP1.Request.CharSet := 'utf-8';
try
sResponse := IdHTTP1.Post('http://....', JsonToSend);
except
on e : Exception do
begin
ShowMessage(e.Message); // this message is : HTTP/1.1 404 Not Found
Exit;
end;
end;
finally
JsonToSend.Free;
end;