.NET HttpWebRequest/Response

Elmo187

Limp Gawd
Joined
Jun 7, 2003
Messages
291
I am using HttpWebRequest and HttpWebResponse in VB.NET to check the timestamp of a specific file which i know is updated periodically(every 4-10 minutes or so). The thing is, it seems like this is caching results because there is a lag between when the file is updated and when my program sees that the file has been updated. But the IsFromCache value of the response object returns false.

If I navigate to the directory listing and check the timestamp myself, I can see that the file has been updated, but if I then run my program, it will still return the old timestamp.

This is the code that gets the timestamp.

Code:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] request [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] HttpWebRequest
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] response [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] HttpWebResponse
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] client [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] WebClient()
client.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials
request = [/SIZE][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][SIZE=2](WebRequest.Create(([/SIZE][SIZE=2][COLOR=#a31515]"http://"[/COLOR][/SIZE][SIZE=2] & fileName)), HttpWebRequest)
response = [/SIZE][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][SIZE=2](request.GetResponse(), HttpWebResponse)
serverTime = response.LastModified
response.Close()
[/SIZE]
Any thoughts on this?
 

xappie

[H]ard|Gawd
Joined
Dec 13, 2000
Messages
1,378
Maybe there is a delay between when the file is modified, and when the webserver hosting the file detects this change and updates the last modified value?
 

Elmo187

Limp Gawd
Joined
Jun 7, 2003
Messages
291
Thats possible, but then why if I browse to the directory myself, would I see the correct timestamp? Thats whats throwing me off.
 

xappie

[H]ard|Gawd
Joined
Dec 13, 2000
Messages
1,378
I dont know for sure, but i THINK that the timestamp that is returned by the webserver for "last modified" is cached and not updated immediately.

What webserver are you running?
 

Elmo187

Limp Gawd
Joined
Jun 7, 2003
Messages
291
Its not my server, I'm just grabbing files from it, but they are running apache 2.0.52
 

simpsond

Weaksauce
Joined
Feb 2, 2005
Messages
119
Can you simply analyze the content for differences rather than the timestamp?
 

mikeblas

[H]ard|DCer of the Month - May 2006
Joined
Jun 26, 2004
Messages
12,775
Since you're concerned with the caching of the response, it seems like you should be setting the CachePolicy on your web request object.
 

Elmo187

Limp Gawd
Joined
Jun 7, 2003
Messages
291
Can you simply analyze the content for differences rather than the timestamp?

Its not really possible because of the nature of the data. But I did find a different solution, it turns they have an FTP site, and it appears that the timestamp weirdness has something to do with the mirroring between the FTP and the HTTP servers.
 
Top