Search code examples
ioscocoa-touchios4xcode4.2asihttprequest

ASIHTTPRequest Get Request - Delegate Not Getting Called


My request is

        NSURL *requestUrl = [NSURL URLWithString:url];

    if(request_) {
        [request_ setDelegate:nil];
        [request_ release];
    }
    request_ = [[ASIFormDataRequest requestWithURL:requestUrl] retain];
    [request_ setDelegate:self];
    [request_ setRequestMethod:@"GET"];
    [request_ setTimeOutSeconds:HTTP_TIME_OUT];
    [request_ startAsynchronous];

The call is going since the network access indicator on the top bar is rotating and disappearing after a few seconds. But either of the delegate methods

- (void)requestFinished:(ASIHTTPRequest *)request

or

- (void)requestFailed:(ASIHTTPRequest *)request

is not being called. What could have went wrong?

Thanks in advance.

PS: Sometimes, due to some issue, server is returning a "500 Internal Server Error". But even in that case, shouldn't the delegate

- (void)requestFailed:(ASIHTTPRequest *)request

be called?


Solution

  • you can use the blocks to check that out.

    here is the example of the same:

     NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
       __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
       [request setCompletionBlock:^{
          // Use when fetching text data
          NSString *responseString = [request responseString];
    
          // Use when fetching binary data
          NSData *responseData = [request responseData];
       }];
       [request setFailedBlock:^{
          NSError *error = [request error];
       }];
       [request startAsynchronous];
    

    I hope this might help.