Share via

OnChttpFile->Seek() failes! MFC

drjackool 956 Reputation points
2021-09-04T03:50:00.74+00:00

Hi
When I use INTERNET_FLAG_DONT_CACHE, the Seek() function throw an exception but when remove this flag it works! also when I combine INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_HYPERLINK it works again. Why?
Also server supports accept-ranges.

What is correct flag to download a file without out using the cache? What is difference between INTERNET_FLAG_RELOAD and mentioned flags?
Thanks

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

0 comments No comments

2 answers

Sort by: Most helpful
  1. YujianYao-MSFT 4,296 Reputation points Microsoft External Staff
    2021-09-07T08:11:51.973+00:00

    Hi,

    When I use INTERNET_FLAG_DONT_CACHE, the Seek() function throw an exception but when remove this flag it works! also when I combine INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_HYPERLINK it works again. Why?

    CInternetFile::Seek is currently implemented using InternetSetFilePointer system function. If the data is not available from the cache and the server does not support random access might block or return pending.

    This handle must not have been created with the INTERNET_FLAG_DONT_CACHE or INTERNET_FLAG_NO_CACHE_WRITE value set.

    What is correct flag to download a file without out using the cache?

    I suggest you could try to use INTERNET_FLAG_RELOAD flag to download a file without out using the cache.

    Here is the code:

    CInternetSession interSession(L" ", 1, PRE_CONFIG_INTERNET_ACCESS, NULL  
    		, NULL, 0);  
    	CHttpFile* pf = (CHttpFile*)interSession.OpenURL(url, 1,  
    		INTERNET_FLAG_RELOAD);  
    

    What is difference between INTERNET_FLAG_RELOAD and mentioned flags?

    INTERNET_FLAG_DONT_CACHE
    Does not add the returned entity to the cache. This is identical to the preferred value, INTERNET_FLAG_NO_CACHE_WRITE

    INTERNET_FLAG_HYPERLINK
    Forces a reload if there is no Expires time and no LastModified time returned from the server when determining whether to reload the item from the network. This flag can be used by FtpFindFirstFile, FtpGetFile, FtpOpenFile, FtpPutFile, HttpOpenRequest, and InternetOpenUrl.

    INTERNET_FLAG_RELOAD
    Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. The FtpFindFirstFile, FtpGetFile, FtpOpenFile, FtpPutFile, HttpOpenRequest, and InternetOpenUrl functions use this flag.

    For more details, I suggest you could refer to the Doc: API Flags

    Best Regards,

    Elya


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


  2. Castorix31 91,876 Reputation points
    2021-09-04T08:08:47.897+00:00

    You can see this thread : Seek CHttpFile Problem
    or you can also use URLDownloadToFile

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.