I'm trying to connect to a website(server) and get information. I use a URL string that works perfectly when I copy it to the Safari browser but when I try to perform the same task in the code, nothing happens.
I use the standard asynch NSURLConnection procedure:
When debugging, I can see that the request object and the connection objects are not nil (i.e. there is no connection failure) but the delegate methods are never called (I put a break point in each of them). Is there something I forgot to add? should the class executing the connection inherit from a special class(other than NSObject)? should I import a class or framework apart from: #import <Foundation/Foundation.h>.
Why is there no call for the connection delegate methods?
Any ideas?
Thanx in advance,
WSD
I use the standard asynch NSURLConnection procedure:
Code:
NSURLRequest *request = [[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:URLstr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0] autorelease];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection) {
// Create the NSMutableData that will hold
// the received data
self.responseData=[[NSMutableData data] retain];
}
else {
NSLog(@"Connection Failure!");
self.responseData = nil;
}
I also added connection delegate methods such as:
- (void)connectionNSURLConnection *)connection didReceiveResponseNSURLResponse *)response {
[responseData setLength:0];
}
- (void)connectionNSURLConnection *)connection didReceiveDataNSData *)data {
[self.responseData appendData:data];
}
- (void)connectionNSURLConnection *)connection didFailWithErrorNSError *)error {
[responseData release];
[connection release];
// Show error message
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}
Why is there no call for the connection delegate methods?
Any ideas?
Thanx in advance,
WSD