I am facing a weird problem in downloading xml files from server.
I am trying to get schedulist.xml using the following code,
- (void) downloadXml:(NSString*)url {
_urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[_urlRequest setHTTPMethod:@"GET"];
if(_urlConnection !=NULL)
return NO;
_urlConnection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self startImmediately:YES];
}
The problem is ,
didReceiveResponse,didReceiveData and connectionDidFinishLoading.
FYI , I have deleted the old response data.But the thing is , If I use [_urlRequest setHTTPMethod:@"POST"];
It is working fine, which is
didFailWithError
is getting calledWhat could be the problem ?
By default NSURLRequest
uses protocol data to decide whether to cache request or not.
For example, if "Cache-control" or "Expires" directives are present in response headers (RFC2616), their values will be used to decide if cached response can be used as it is.
Usually only GET requests are cached, that's why you get didFailWithError
on your POST
request.
To avoid caching you can fix headers on your server or set cachePolicy
property of NSURLRequest
to NSURLRequestReloadIgnoringLocalCacheData