0

Im using codes posted here:
connection release method in connectionDidFinishLoading, causes error

now first execute returns didFail log. second execute; returns old response data. albeit my (localhost) server is totally offline. and cachePolicy is NSURLCacheStorageNotAllowed (check the code on the link I posted above)

 NSMutableURLRequest *request=
[NSMutableURLRequest requestWithURL:url 
cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:3.0f];

the response data seems cached somewhere and still exists.

but if I use NSURLRequestReloadIgnoringLocalAndRemoteCacheData //which is commented as -not implemented-

not returns old cache.

but if so what is the difference between:
NSURLRequestReloadIgnoringLocalAndRemoteCacheData
and
NSURLCacheStorageNotAllowed

what shall I do ?

Community
  • 1
  • 1
Zen Of Kursat
  • 2,323
  • 26
  • 43

2 Answers2

2

NSURLCacheStorageNotAllowed refers to NSCachedURLResponse and is an value of enum NSURLCacheStoragePolicy. Since the cache policy of NSMutableURLRequest is also an enum (NSURLRequestCachePolicy) you just pass wrong int to the static method creating NSMutableURLRequest. In this case NSURLCacheStorageNotAllowed is just 2 which equals to NSURLRequestReturnCacheDataElseLoad - and that is why you get old data.

Wladek Surala
  • 2,392
  • 1
  • 23
  • 30
0

Try This

NSString *Post = [[NSString alloc] initWithFormat:@"Post Parameters"]; NSURL *Url = [NSURL URLWithString:@"Url"];

    NSData *PostData = [Post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d", [PostData length]];

    NSMutableURLRequest *Request = [[NSMutableURLRequest alloc] init];
    [Request setURL:Url];
    [Request setHTTPMethod:@"POST"];
    [Request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [Request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [Request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [Request setHTTPBody:PostData];
  NSError *error;
    NSURLResponse *response;

    NSData *Result = [NSURLConnection sendSynchronousRequest:Request returningResponse:&response error:&error];
    if (!Result)
    {
        NSLog(@"Error");
    }
    else
    {
       //Parse the result
    }
iAppDeveloper
  • 1,088
  • 1
  • 8
  • 16
  • your example is synchronous.thus it hangs application till server receiving finalized. Question is why NSURLCacheStorageNotAllowed allows ? it still returns old cache data if server is offline. your answers are not relevant to question. I dont want a way to pass this with another method. I wanto learn the reason. – Zen Of Kursat Sep 12 '13 at 07:44