2017-03-16 59 views
1

当印地收到了404,我不能得到的回应内容,其总是空的没有反应的内容。德尔福印后404

例如,使用印地访问https://www.etsy.com/people/car,我得到一个404和contentstream(或分配流)仅仅是空的。 与THttpClient一样,我也得到了404,但也得到了响应流中404页面的内容。

所以我的问题是,如何才能得到响应内容与印时,其404?

+0

是存储在EIdHTTPProtocolException'的'了'ErrorMessage'的内容,像印第403错误:http://stackoverflow.com/questions/607876/indy-http-reading-response-content-on -a-403 –

回答

5

using Indy to access  https://www.etsy.com/people/car , I get a 404 and contentstream (or assigned stream) is just empty.

这是设计时的默认行为,用于防止使用未请求的意外错误数据来破坏输出。

how can I get the response content with Indy when its a 404?

有两种可能的方式:

  1. 默认情况下,TIdHTTP提出了一个HTTP错误的EIdHTTPProtocolException例外。响应数据将在其ErrorMessage属性中。

  2. 您可以通过避免引发的异常:

    • 使hoNoProtocolErrorException国旗在TIdHTTP.HTTPOptions财产。

    • 使用TIdHTTP.Get()的重载版本,它具有AIgnoreReplies参数,并在该参数中传递404(或任何其他所需的错误响应代码)。

    无论哪种方式,通过默认响应数据将仍然被丢弃。您可以避免在TIdHTTP.HTTPOptions属性中启用最近添加的hoWantProtocolErrorContent标志(请参阅New TIdHTTP flags and OnChunkReceived event)。

+0

谢谢雷米,回答完全接受。我使用ErrorMessage值,它现在工作得很好! – Softtouch