views:

36

answers:

2

I have

-(void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"Request Failed Error: %@", error);
}

When I make my request I do

    //add data to the array
    NSString *json = [array JSONRepresentation];
[request appendPostData:[json dataUsingEncoding:NSUTF8StringEncoding]];

[request startAsynchronous];

I'm getting this in my log:

 0-08-11 16:52:11.652 MyProject[11720:207] Starting asynchronous request <ASIHTTPRequest: 0x5a7df10>

2010-08-11 16:52:11.861 MyProject[11720:207] Request finished downloading data 2010-08-11 16:52:11.861 MyProject[11720:207] Request failed: (gdb)

But my log statement in

 -(void)requestFailed

is not getting called. Any ideas?

Cheers

+1  A: 

Did you set the request's delegate and didFailSelector properties? Usually:

[request setDelegate:self];
[request setDidFailSelector:@selector(requestFailed:)];

suffices if the -requestFailed: method is in the same class implementation file.

Also set the didFinishSelector property to call a local selector when then request finishes correctly.

Alex Reynolds
-requestFailed: is the default failure selectors, so it shouldn't be necessary to set this (though equally it does no harm). Spot on with the setDelegate though, seems the most likely cause.
JosephH
Thanks - I did set these, I forgot to include the name of the object when I sent the message, instead sending only a dictionary list.
quantumpotato
A: 

-requestFailed: is only returned when a request can't be completed - eg. failure to contact the server, or the server didn't conform to the http protocol.

If request can be completed, requestFinished will be called, and you can then check the http status code there, which may indicate a failure. responseStatusText may give more information as to what the failure was.

JosephH
Thanks - forgot to set the name of the object I was sending, instead only sending the list of parameters for that object.
quantumpotato