> I would like to restart a connection re-invoking [request
> startAsynchronous] if for example the first request does not return
> expected results.
> The problem is that the second attempt to call startAsynchronous raise
> an exception:
>
> *** Terminating app due to uncaught exception
> 'NSInvalidArgumentException', reason: '*** -[NSOperationQueue
> addOperation:]: operation is finished and cannot be enqueued'
Yes, you cannot restart a request like this.
One option would be to make a copy of your request, and start that:
ASIHTTPRequest *newRequest = [[request copy] autorelease];
[newRequest startAsynchronous];
But, if you're just doing a simple GET request, you can just as easily create a new request with the same url.
Best
Ben
- (void)dealloc {
[request clearDelegatesAndCancel];
[request release];
[super dealloc];
}
- (void)sendRequest {
[request clearDelegatesAndCancel];
[request release];
NSURL *url = [[NSURL alloc] initWithString:@"https://example.com/"];
request = [[ASIFormDataRequest alloc] initWithURL:url];
[url release];
request.delegate = self;
[request setPostValue:@"value1" forKey:@"key1"];
[request setPostValue:@"value2" forKey:@"key2"];
[request setPostValue:session forKey:@"iVarKey"];
[request startAsynchronous];
}
The first time i call -sendRequest, request will be nil. That should be fine. Any time after the first that I call it, the first two lines should reset the request correctly, right?
Thanks!
Matt
[request clearDelegatesAndCancel];
[request release];
Or, should I just create an ASIHTTPRequest category and define a method that does the above?
I'm asking because I want to write this code in four spots: dealloc, sendRequest, requestFinished, and requestFailed.
Thanks!
Matt
Wait, if I call [request release] will that call my delegate and/or queue�s failure delegate methods like [request cancel] does? If not, then can I just do [request release] in sendRequest, requestFinished, and requestFailed; and do both [request�clearDelegatesAndCancel] and then [request release] in dealloc?