?
Solved

InternetOpenUrl keeps using cache file instead of Web file

Posted on 2016-10-24
9
Medium Priority
?
83 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
9 Comments
 
LVL 35

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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

752 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