I try to retrive data from certain url with command:
-(NSMutableData *) callUrl: (NSString *)url withData:(NSMutableDictionary *)data delegate:(id) delegate {
NSURL *executeUrl = [NSURL URLWithString:<string>];
NSURLRequest *request = [NSURLRequest requestWithURL: executeUrl
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60];
NSMutableData *receivedData = nil;
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:delegate];
if (theConnection) {
receivedData = [[NSMutableData data] retain];
} else {
@throw @"Connection error";
}
return receivedData;
}
In delegate (both after connectionDidFinish and connectionDidFailWithError) I do:
//some uninvasive alerts
// release the connection, and the data object
[connection release];
[receivedData release];
Problem is when I provide bad url I got proper error - it's good part - but then I want to execute second url - good for sure, I've got 1003 error - NSURLErrorCannotFindHost.
After around 1-2 min I'm succesfully call url and get data. I suspect some timeouts and ports business, but changing timeout in NSURLRequest doesn't change a thing.
UPDATE
As it turned out - Administrators had some issues with DNS server reached through WiFi network. Code is fine. Thanks for response. If some has similiar problems: try ip address instead of hostname.