Search code examples
iphoneobjective-casihttprequestasiformdatarequest

EXC_BAD_ACCESS in ASIHTTPRequest / ASIFormDataRequest


I am running into issues using ASIFormDataRequest. The request seems to be made but when I try to access the request once it has completed I get an EXC_BAD_ACCESS error. After looking around I can see no issue with what I'm doing hence me turning here. Can anyone spot what I am doing wrong?

I got the basics of the code here.

- (void)viewDidLoad
{
    /* Stuff here */
    NSURL *url = [NSURL URLWithString:@"http://www.mysite.com/login"];
    ASIFormDataRequest *request1 = [ASIFormDataRequest requestWithURL:url];
    [request1 setPostValue:@"email@email.com" forKey:@"email"];
    [request1 setPostValue:@"pass123" forKey:@"password"];
    [request1 setDelegate:self];
    [request1 startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)thisRequest
{    
    NSLog(@"Request FInished: %@", thisRequest.responseStatusCode); //crashes here

    if (thisRequest.responseStatusCode == 403){
        NSLog(@"403 Not authorised");
    }
    if (thisRequest.responseStatusCode == 200)
    {
        NSLog(@"Data: %@", thisRequest.responseString);
    }
}

Solution

  • The issue isn't the request being bad, its that you're trying to print an int as an object. Change this:

    NSLog(@"Request FInished: %@", thisRequest.responseStatusCode);
    

    to this

    NSLog(@"Request FInished: %d", thisRequest.responseStatusCode);
    

    or NSLog(@"Request FInished: %@", thisRequest); (if you want to print the full request description)

    You're effectively trying to say "print the object at address 0xresponseStatusCode" which isn't a valid object.