Solved

InternetOpenUrl keeps using cache file instead of Web file

Posted on 2016-10-24
9
64 Views
Last Modified: 2016-11-16
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
0
Comment
Question by:Thierry TGMDev
  • 2
  • 2
9 Comments
 
LVL 33

Expert Comment

by:sarabande
ID: 41858089
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
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 500 total points
ID: 41859518
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
 

Author Comment

by:Thierry TGMDev
ID: 41864482
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
 

Accepted Solution

by:
Thierry TGMDev earned 0 total points
ID: 41866218
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
 
LVL 40

Expert Comment

by:evilrix
ID: 41886205
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 82
HTTPSendRequest with WinINet delays on first call 11 28
Outlook 13 39
learn programming 8 30
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question