Q:

Detect HTTP code 302 from webView

I need to detect HTTP code 302 after the user introduces the correct login and password, I'm using this method:
- (void) connection:(NSURLConnection *)connection
 didReceiveResponse:(NSURLResponse *)response
{
    NSLog(@"connection:didReceiveResponse");

    if ([response isKindOfClass:[NSHTTPURLResponse class]]) {

        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;

        int status = [httpResponse statusCode];

        if (status == 302) {

            //do something here
        }

        else
        {

            NSLog(@"http status code: %d", status);
        }

        [connection cancel]; 

    }

}

However I can only get status code 200 after the page is redirected, any idea please??
Thanks!

A:

if you are using UIWebView then you need to check the error code within the delegate method of UIWebViewDelegate, not in the didReceiveResponse of NSURLConnectionDelegate.
this is the exact method where you can check the error code..
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    if (error.code == ERROR_YOU_WANT_TO_CHECK {
       //do what you want to do here 
     }
}

EDIT
in case you are using NSURLConnection then answer to this question might help your cause 

