How to retrieve a file from Internet via HTTP?

后端 未结 6 2151
天命终不由人
天命终不由人 2020-12-30 17:46

I want to download a file from Internet and InternetReadFile seem a good and easy solution at the first glance. Actually, too good to be true. Indeed, digging a bit I have s

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 18:11

    I basically do the same as you do. For me it works fairly flawlessly.

    The only differences between my code and your code is I have an INTERNET_FLAG_RELOAD parameter to force a download from the file and not the cache. You can try that and see if it works better:

      hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, INTERNET_FLAG_RELOAD, 0) ; 
    

    Also check for an internet connection before downloading. Do this:

      dwConnectionTypes := INTERNET_CONNECTION_MODEM
                     + INTERNET_CONNECTION_LAN
                     + INTERNET_CONNECTION_PROXY;
      InternetConnected := InternetGetConnectedState(@dwConnectionTypes, 0);
      if InternetConnected then ...
    

提交回复
热议问题