Delphi:Indy - 如何让错误的响应体? [英] Delphi: Indy - how to get the response body on error?

查看:884
本文介绍了Delphi:Indy - 如何让错误的响应体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi6和XE3。

Delphi6 and XE3.

我想获得一个请求的真实响应体。
但是服务器发生错误500.
然后Indy用错误的描述替换响应文本。

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 the error.

此主页专为回答500在非异常操作中,我们需要确定从响应文本中做什么。

This homepage is designed for answer 500 in non abnormal operations too, and we need to determine what to do from response text.

可以从IdHTTP或异常对象获取响应文本代码为500?

Could I get the response text from IdHTTP or from an Exception object when the status code is 500?

感谢任何信息!

推荐答案

TIdHTTP 遇到服务器错误,它引发了一个 EIdHTTPProtocolException 异常,其中 ErrorCode 属性包含HTTP状态代码(500等),其消息属性包含HTTP状态文本(内部错误等)及其 ErrorMessage 属性包含响应的正文文本(如果有)。所以,例如:

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;

这篇关于Delphi:Indy - 如何让错误的响应体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆