Reputation:
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!
Upvotes: 2
Views: 2771
Reputation: 12671
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
Upvotes: 1