InternetOpenUrl keeps using cache file instead of Web file

I have a file in my web site (URL stored in strURL) that change regularly. I'd like to read it but, after a change, it keeps giving the information in the cache, even with DeleteUrlCacheEntry saying that there is no file in cache !!!  

Here is the code (with errors handling removed)

DeleteUrlCacheEntry(strURL)

m_hInet = InternetOpen(strAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

m_hConnect = InternetOpenUrl(m_hInet, strURL, NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE, NULL);

Open in new window


I also check the header but it does not return an error (as the file really exist in the web site !!)
BOOL bQueryResult = HttpQueryInfo(m_hConnect, HTTP_QUERY_STATUS_CODE, (LPVOID)szBuffer, &dwSize, NULL);

InternetReadFile(m_hConnect, szBuffer, 512, &dwRead);

Open in new window


What is wrong with this code ????  Compiled with Visual Studio 2015 in Windows 10.

Thanks for your help

Thierry
Thierry TGMDevAsked:
Who is Participating?
 
Thierry TGMDevAuthor Commented:
Hello All

Using DeleteUrlCacheEntry  is clearly a good way to get rid of the cache copy for Internet files. I tried different options using InternetSetOption function but none were enough.
Then I check the idea sent by evilrix. I browse the web and made some changes to the .htaccess file at the root of the web site. After a few attempts, I finally got it. The file is not cached anymore on the SERVER side. As I got rid of the local cache, using the original code (shown on the first question) is in fact Ok.

Thanks to all for driving to the right solution

Thierry
0
 
sarabandeCommented:
what are the return values both of HttpQueryInfo and InternetReadFile?

why didn't you initialize the dwSize value (to 512) passed to HttpQueryInfo?

why didn't you check the retrieved http header before reading the file?

see example how to properly use HttpQueryInfo at

  https://msdn.microsoft.com/en-us/library/windows/desktop/aa385373(v=vs.85).aspx 

see example how to call InternetReadFile at

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa384322(v=vs.85).aspx

Sara
0
 
evilrixSenior Software Engineer (Avast)Commented:
Have you checked the options you're setting on the connection? You can set an option to by-pass cached content and always pull a new version.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa385328(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/aa385114(v=vs.85).aspx

I believe the option you are looking for is INTERNET_OPTION_BYPASS_EDITED_ENTRY

Also, check to make sure that your ISP isn't using a transparent proxy. Sometimes ISPs cache stuff their end to reduce their network load. One trick you can use is to put a question mark at the end of the URL as this tells the browser that the URL contains a query option and, as such, not to cache the results. This trick doesn't always work, but it's worth trying as it might also fool the transparent proxy if your ISP is using one.

https://en.wikipedia.org/wiki/Proxy_server#Transparent_proxy
0
 
Thierry TGMDevAuthor Commented:
Clearly I do not abandon the issue. I'm still working to find out how to use InternetSetOption. very few example on the Web and none for the option INTERNET_OPTION_BYPASS_EDITED_ENTRY


Thanks for your help. I'll keep you informed

Thierry
0
 
evilrixSenior Software Engineer (Avast)Commented:
Since this seems to be a server side issue and I suggested that some kind of transparent proxy could be the cause, I'd have though that would have at least warranted an assist, especially has you have indicated it pointed you in the right direction.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.