Delphi Indy no response content after 404

北城以北 提交于 2020-01-20 08:16:52

问题


When Indy get a 404, I cannot get the response content, its always empty.

For example, using Indy to access https://www.etsy.com/people/car, I get a 404 and contentstream (or assigned stream) is just empty. Doing the same with THttpClient, I also get a 404, but also get the content of the 404 page in the response stream.

So my question is, how can I get the response content with Indy when its a 404?


回答1:


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

This is the default behavior, by design, to prevent corrupting the output with unexpected error data that was not requested.

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

There are two possible ways:

  1. By default, TIdHTTP raises an EIdHTTPProtocolException exception on an HTTP error. The response data will be in its ErrorMessage property.

  2. You can avoid the raised exception by either:

    • enabling the hoNoProtocolErrorException flag in the TIdHTTP.HTTPOptions property.

    • using the overloaded version of TIdHTTP.Get() that has an AIgnoreReplies parameter, passing 404 (or any other error response code you want) in that parameter.

    Either way, by default the response data will still be discarded. You can avoid that by enabling the recently added hoWantProtocolErrorContent flag in the TIdHTTP.HTTPOptions property (see New TIdHTTP flags and OnChunkReceived event).



来源:https://stackoverflow.com/questions/42825123/delphi-indy-no-response-content-after-404

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!