How to get response content even if the connection gives an error in IdHttp?

When using TIdHttp, for example:

Memo1.Text := IdHTTP1.post(url,data); 

I can get the content response in memo1 if it does not give an HTTP error. But when he gives an http request, Indy doesn't give me the content. I also use try..except, but it only prevents the error and still does not give me the content.

How can I get content even if it returns an HTTP error?

+4
source share
2 answers

When an HTTP error TIdHTTP throws an EIdHTTPProtocolException . This exception contains the HTTP status code in the ErrorCode , the HTTP status text in the Message property, and the response data in the ErrorMessage property.

+6
source

try this code

 Try Memo1.Text := IdHTTP1.post(url,data); except on e: EIdHTTPProtocolException do begin memo1.lines.add(idHTTP1.response.ResponseText); memo1.lines.add(e.ErrorMessage); end; 

e.ErrorMessage will provide you some bad request information.

+2
source

Source: https://habr.com/ru/post/1499937/


All Articles