I am trying to connect to an HTTPS site 开发者_如何学Pythonasynchronously with the following code.
Absolutely nothing occurs. The setRequestDidFinishSelector or setRequestDidFailSelector are never called... - I have attempted to test it by setting the request to Synchronous and it works. - I also attempted to try using a __block as per ASIHTTPRequest documentation, and it also works.Can anyone please help?
Thx!
- (NSArray*) requestAccessForUser: (NSString*) user
withPassword:(NSString*) password
{
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:authPageURL];
[request setPostValue:user forKey:@"user"];
[request setPostValue:password forKey:@"pwd"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request setRequestDidFailSelector:@selector(requestFailed:)];
[request setRequestDidFinishSelector:@selector(requestFinished:)];
[request setTimeOutSeconds:30];
//[request startSynchronous]; // <= This works
[request startAsynchronous]; // <= This crashes
}
- (void)requestFinished:(ASIHTTPRequest *)request{
NSLog(@"requestFinished: %@", [request responseString]);
}
- (void)requestFailed:(ASIHTTPRequest *)request{
NSError *error = [request error];
NSLog(@"oops: %@", [error localizedDescription]);
}
In your code you are setting the selector setQueueDidFinishSelector instead of setRequestDidFinishSelector. In fact, if your class does conform the ASIHTTPRequestDelegate protocol you don't need to set those selectors, they will be called by default.
精彩评论