Using Win API URLDownloadToFile_()

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

When using URLDownloadToFile API function allows to cache a Web page in a local file for any further parsing or storage.

The problem is that the file is cached through the standard Internet layer of Windows and if the file was previously cached on the local machine it is not reloaded by the URLDownloadToFile function.

URLDownloadToFile_(0, YourURL, YourFile, 0, 0)
DeleteUrlCacheEntry_(YourURL)

is a simple way to force the cache to delete the page's image and to reload it the next time.

This is especially handy for regular pages checks (when accessing dynamic content for example) and make it an easier way rather than using InternetOpen_() InternetOpenFile_() and InterReadFile_() with specific flags for forcing page's reload.


Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> DeleteUrlCacheEntry_(YourURL) is a simple way to force the cache to
> delete the page's image and to reload it the next time.

Thanks for that, Francois; I've added it to my apps. :)


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

Thanks Fweil a lot, couse I want to use URLDownloadToFile to download actual serverlists for our sharing-tool. Would be silly to download cached - old - serverlists with dead servers.

But you prevent this problem. :) hehe

Thanks
Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

...

All this API Internet stuff is tricky but while searching we can find some good and short ways to solve our issues !!! (:>)

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

IMPORTANT TIP FOR THIS API COMMAND!

The URLDownloadToFile API command is extremely useful, but I just want
to ensure that you all remember this very important tip: Make sure that
your app makes it clear in its docs that it doesn't contain "spyware"
of any kind! Using this API command will set off warning bells in many
firewall apps (such as ZoneAlarm) and the last thing you want to do is
scare off new users of your app who think it's trying to spy on them,
or "phone home", as they say. So make sure you put their concerns to
rest in your docs, and explain why your app is accessing the Internet
before it does so. Trust me on this -- I went through it. :)


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

You are right PB. I always give a networking security notice to customers anyway, even without this specific function. As soon as you use MS stuff, think to give an explicit notice relating too security issues.

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

One thing I just learnt about this tip: The DeleteUrlCacheEntry API
is not available under Windows 95, and will crash your app if you try
to use it on that OS...


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

Sorry that I could not check about all OS versions compatibility. By the way I always use 2K, sometime NT4 or 98 ... for my coding and tests.

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Sorry that I could not check about all OS versions compatibility.

No need to apologize; I was just letting people know.


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by danny.


I have a problem with DeleteUrlCacheEntry on some XP systems.
I haven't encountered it myself, but the problem seems to occur every once in a while on a client XP machine: I call DeleteUrlCacheEntry prior to calling URLDownloadToFile, in order to ensure that the file will NOT be downloaded from the cache - however sometimes, on XP, it nevertheless comes from the cache, and the user gets an older version than the one on the server.

Any idea?

Thanks!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> I call DeleteUrlCacheEntry prior to calling URLDownloadToFile

I think you have to call it after, not before, but I haven't tested
this to be 100% sure. Give it a try and let us know what happens.


PB - Registered PureBasic Coder
berklee
User
User
Posts: 36
Joined: Wed Jul 28, 2004 3:45 pm

Post by berklee »

It'd sure be nice to have a cross-platform means of using TCP/IP. I'm surprised it's not in place already, especially considering that ODBC is.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

berklee: winsock?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
berklee
User
User
Posts: 36
Joined: Wed Jul 28, 2004 3:45 pm

Post by berklee »

Anything. I have an app I have to write that requires cross-platform functionality (think of it as an RSS reader). But the problem seems to be that if I want to download a file from the internet, the mechanics need to be completely different for each OS.

It would be real nice to have some sort of wrapper to handle simple HTTP POST/GET transactions... I'm sure I can figure it out under Windows, but I'd hate to suffer a massive code rewrite to put it under Linux...

I guess this means I'm looking for a cross-platform TCP/IP gadget...
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

@berklee

I supose this is what you are looking for ;)

viewtopic.php?t=11095
Post Reply