0

When using IDHTTP to send POST commands with JSON variables, sometimes the server returns me the exception below :

HTTP/1.1 500 Internal Server Error

I know this is a server side error and probably there is something wrong with my request JSON data.

BUT if i run the same POST command using Chrome, the browser will show a more detailed error in the page content, instead of the simple HTTP 500. Is there a way to also receive these details using IDHTTP ?

Here is an example of my code :

idhttp1.Request.ContentType := 'application/json';
idhttp1.post(URL, JsonToSend); //this line will throw the exception
delphirules
  • 6,443
  • 17
  • 59
  • 108
  • 1
    Handle the [EIdHTTPProtocolException](http://www.indyproject.org/docsite/html/frames.html?frmname=topic&frmfile=EIdHTTPProtocolException.html) exception. – Victoria Jan 17 '18 at 16:22
  • 1
    @Victoria note that `EIdHTTPProtocolException` is not raised if the `hoNoProtocolErrorException` flag is enabled, or `500` is passed in the `AIgnoreReplies` parameter of the request. In which case, the body data is discarded unless you enable the `hoWantProtocolErrorContent` flag. See [New TIdHTTP flags and OnChunkReceived event](http://www.indyproject.org/Sockets/Blogs/ChangeLog/20160110.EN.aspx) – Remy Lebeau Jan 17 '18 at 17:11

1 Answers1

0

I just found out that IDHTTP has a Response.RawHeaders property. So to read the details , just read this property after posting.

IDHTTP.Response.RawHeaders.Text;
delphirules
  • 6,443
  • 17
  • 59
  • 108
  • 1
    That gives you access only to the response headers, not the response body data, which is what a browser would display. By default, that data is stored only in the `EIdHTTPProtocolException` that gets raised – Remy Lebeau Jan 17 '18 at 17:06