Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using System.Net.WebClient and no cache

352 views
Skip to first unread message

Fenster

unread,
Oct 7, 2008, 7:12:58 PM10/7/08
to
I've written a script to grab a web page but I need to ensure the page
is not cached and test.html is the latest version:

$url = "http://www.example.com/test.html"
$webClient = new-object System.Net.WebClient
$output = $webClient.DownloadString($url)

I see that System.Net.WebClient has a CachePolicy property, but I
don't really know how to implement it in this example. Any ideas?

PaulChavez

unread,
Oct 7, 2008, 8:59:01 PM10/7/08
to
Try this:

[System.Reflection.Assembly]::LoadWithPartialName("System.Net.Cache")
$policy = new-object System.Net.Cache.RequestCachePolicy("BypassCache")

and then you can set the CachePolicy property to the $policy object.

-Paul

Fenster

unread,
Oct 8, 2008, 11:42:36 AM10/8/08
to
Not sure if I'm doing this right, but it keeps pulling the cached
version, this is what I've done:

$url = "http://www.weatheroffice.com/scripts/nphshowarf.pl?
html&1010.txt"

[System.Reflection.Assembly]::LoadWithPartialName("System.Net.Cache")
$policy = new-object
System.Net.Cache.RequestCachePolicy("BypassCache")

$webClient = new-object System.Net.WebClient
$webclient.CachePolicy.($policy)

$output = $webClient.DownloadString($url)
$webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE
5.5; Windows NT 5.0)")

On Oct 7, 5:59 pm, PaulChavez <PaulCha...@discussions.microsoft.com>
wrote:

> > don't really know how to implement it in this example.  Any ideas?- Hide quoted text -
>
> - Show quoted text -

PaulChavez

unread,
Oct 8, 2008, 1:23:01 PM10/8/08
to
I was taking an educated guess at which enumeration to use from this page:
http://msdn.microsoft.com/en-us/library/system.net.cache.requestcachelevel(VS.80).aspx

You may want to experiment with these cache levels a bit.

Paul

0 new messages