Delphi: Indy - how to get the response body on error?

前端 未结 1 1630
鱼传尺愫
鱼传尺愫 2020-12-09 20:56

Delphi6 and XE3.

I want to get the real response body of a request. But the server makes error 500. Then the Indy replace the response text with the description of t

相关标签:
1条回答
  • 2020-12-09 21:38

    When TIdHTTP encounters a server error, it raises an EIdHTTPProtocolException exception, where its ErrorCode property contains the HTTP status code (500, etc), its Message property contains the HTTP status text ("Internal Error", etc), and its ErrorMessage property contains the body text of the response, if any. So, for example:

    try
      IdHTTP1.Get(...);
    except
      on E: EIdHTTPProtocolException do begin
        // use E.ErrorCode, E.Message, and E.ErrorMessage as needed...
      end;
    end;
    
    0 讨论(0)
提交回复
热议问题