Solved

InternetOpenUrl keeps using cache file instead of Web file

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

786 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