iphone - Problems with caching using NSURLConnection and querying HTTP Headers -


i trying write crude app loop round querying of http header fields come server in order find out servers responding ok. servers respond header this: server = server1 (or server2, server 3 etc).

unfortunately when same server name time , time again app unless stop , run again @ point different server back. how can stop happening? need app treat each connection if brand new, seems cache , appear come same place, load balancer returns same server name.

i can replicate similar behaviour(expected) in safari going url repeatedly without shutting down safari - gets same server each time, if shut down safari go new server.

the code using follows:

for (int = 0; < 999; i++) {     request = [nsurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringcachedata timeoutinterval:10];      [nsurlconnection sendsynchronousrequest: request returningresponse: &response error: nil];     if ([response respondstoselector:@selector(allheaderfields)]) {         dictionary = [response allheaderfields];         fullheaderstring = [dictionary description];     } } 

how can make connection treated new 1 every time?

cheers, tom

you can make sure content freshly loaded each time in @ least 2 ways:

  1. add "pragma: no-cache" header http response. should make http client not cache response.
  2. add random query parameter request like: url = "http://myhost.com/controller/blabla?rand=" + math.random(...). make url unique each time server not care parameter still safe.

hope helps


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -