Solved

InternetOpenUrl keeps using cache file instead of Web file

Posted on 2016-10-24
9
49 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 32

Expert Comment

by:sarabande
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now