我正在尝试使用ASIHTTPRequest执行异步请求,但在请求完成时收到通知时有一些问题。
I'm trying to do an asynchronous request with ASIHTTPRequest, but have some problem getting notified when the request is done.
-(void)doDownload{ NSURL *url = [NSURL URLWithString:@"www.someurl/?"]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setPostValue:@"someValue" forKey:@"someField"]; [request setRequestMethod:@"POST"]; [request setDelegate:self]; [request setDidFinishSelector:@selector(requestFinished)]; [request startAsynchronous]; } - (void)requestFinished:(ASIHTTPRequest *)request { // Use when fetching text data NSString *responseString = [request responseString]; }requestFinished永远不会被调用。我在ASIHTTPRequest.m中得到一个异常,-handleStreamCompleted:
requestFinished is never called. I get an exception in ASIHTTPRequest.m, -handleStreamCompleted:
if (fileError) { [self failWithError:fileError]; } else { [self requestFinished]; <----- this call fails }任何线索?
推荐答案你确定你的类实现 - (void)requestFinished:(ASIHTTPRequest *)请求仍然在请求完成时?看起来像我的班级得到释放太早。请注意,委托属性不保留其内容。
Are you sure that your class that implements - (void)requestFinished:(ASIHTTPRequest *)request is still there when the request finishes? It looks to me like the class gets deallocated too early. Note that the delegate property does not retain its content.
您可以添加 [自我保留] to doDownload 和 [self release] to - (void)requestFinished :( ASIHTTPRequest *)请求,但请确保(!) [self release] 也不会调用经常。如果请求永远不会完成,这也可能是内存泄漏。最好保留你的课程在其他地方。
You could add a [self retain] to doDownload and a [self release] to - (void)requestFinished:(ASIHTTPRequest *)request, but make sure (!) that [self release] doesn't get called too often. This is also a possible memory leak if a request would never finish. It would be best to retain your class somewhere else.
您也可以尝试使用 NSZombieEnabled 设置为 YES 找到错误。
You might also try to debug with NSZombieEnabled set to YES to find the error.
更多推荐
ASIHTTPRequest,EXC
发布评论