Reputation: 2063
Before I dive into ASIHttpRequest's source code:
From the documentation (http://allseeing-i.com/ASIHTTPRequest/How-to-use) of ASIHttpRequest it is not completely clear to me when an ASIHttpRequest will call requestDidFinishSelector or requestDidFailSelector.
When does a request fail?
Is it correct to assume that whenever the server responds (with a corresponding HTTP status code, be it a 1xx, 2xx, 3xx, 4xx or 5xx, the request is considered successful, and therefore requestDidFinishSelector will apply? Is 'failure' the fact that the server could not be reached?
As I type this, this seems to be the most logical answer... anyway.
Upvotes: 3
Views: 788
Reputation: 11774
Yes, ASIHTTPRequest
doesn't use HTTP status codes (except for redirection), so it's up to you to look out for problems (ex: 404) in your requestDidFinishSelector
selector.
int statusCode = [request responseStatusCode];
NSString *statusMessage = [request responseStatusMessage];
requestDidFailSelector
will be called only if there is the server can not be reached (time out, no connection, connection interrupted, ...)
Upvotes: 2
Reputation: 3111
You're right — a request succeeds if the server responds with a HTTP status code. You can ask for this status code by using ASIHTTPRequest
's responseStatusCode
.
If the request URL is invalid or your app has no access to the Internet, then your request fails. So you should implement requestDidFailSelector
(or specify your own error handling method) and handle errors in there in any case.
Upvotes: 1