Search code examples
iosasihttprequestresponsensdata

ASIHTTPRequest responseData null


I'm working with ASIHTTPRequest but I have a responseData empty. The response is supposed to be a JSON response and when I try to do this in the browser, it works perfectly.

Here is my code :

- (IBAction)simpleURLFetch {
    NSURL *url = [NSURL URLWithString:@"http://url/url/url"];
    ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url];
    request.timeOutSeconds = 30;
    [request setDelegate:self]; // I correctly set the ASIHTTPRequestDelegate in my .h file
    [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)azrequest {
    NSString *responseString = [azrequest responseString];
    NSData *responseData = [azrequest responseData];

    NSLog(@"repo : %@ / %@", responseData, responseString);
}

And the log displayed this : "repo : (null) / <> /"

Maybe, I'm not using the result with the good way.. Is there a solution to have my JSON response ?

Regards, Sébastien ;)


Solution

  • The problem is that you're not getting data back, not that you're accessing the data incorrectly. The URL in your code is clearly invalid, and I suspect that's not the one you're using. Either way, the request fails to get any data, so there's nothing to log.