-1

Check if it is possible to download file with delphi

Good day ... I'm starting in Delphi and I am creating a program to download files from HTTP ...

I'm using:  

IdHTTP.Get (URL FileDownload)

But my program generates error when it can not download the file ...

Ex: http://exemplo.com/ -> Generates Error

Ex: http://exemplo.com/meudownload.ts -> Makes download

I'd like to correct this error, how can I check if it is possible to download the file or if it is being lowered ...

I used EIdHTTPProtocolExeption but only checks HTML error like: 404, 300 ... and is not that I wish ...

I would like to see if you can download the file, or if it is being downloaded ...

If this happens I will download other file:

donw_1.ts, down_2.TS, down_3.TS ... then when he gets el Archiving one that can not be downloaded, I have the answer to cancel the loop ...

4

3 回答 3

6

抓住EIdHTTPProtocolException是你应该做的。请记住,Indy 是专门为利用异常报告错误而设计的。 EIdHTTPProtocolException是如何TIdHTTP从服务器报告特定于 HTTP 的错误(任何其他类型的异常意味着套接字或 RTL 有问题并且可以重试 HTTP 请求)。您收到该异常的事实意味着服务器无法按请求传递文件,因此您通常不应该重试,除非您知道这是一个可恢复的错误。检查异常ErrorCode是可选的,但如果您确实需要区分特定错误,则可以使用。

于 2014-01-11T20:00:25.487 回答
2

如果您只想查看服务器上是否存在文件,请使用 TIdHTTP.Head。此函数仅下载从等效的 Get 调用返回的标头,而不是数据本身。然后,您可以检查标题以查看文件是否存在并决定下一步做什么。

于 2014-01-11T19:27:37.120 回答
0

无法通过扫描 HEAD 来解决问题 ...并设法解决了 HTTP 404 错误的问题 .... 没有文件可下载的地方会生成此错误 EIdHTTPProtocolExeption ...问题已解决.. ..

于 2014-01-21T13:34:01.073 回答