使用ASIFormDataRequest失败异步请求

时间:2011-01-11 21:17:24

标签: iphone objective-c

我正在尝试使用以下代码异步连接到HTTPS站点 绝对没有任何事情发生。永远不会调用setRequestDidFinishSelector或setRequestDidFailSelector ...
- 我试图通过将请求设置为Synchronous来测试它,它可以正常工作 - 我也尝试按照ASIHTTPRequest文档尝试使用 __ block ,它也有效。

有人可以帮忙吗?

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]);
}   

1 个答案:

答案 0 :(得分:0)

在您的代码中,您正在设置选择器setQueueDidFinishSelector而不是setRequestDidFinishSelector。实际上,如果您的类符合ASIHTTPRequestDelegate协议,则不需要设置这些选择器,默认情况下将调用它们。