I want to do a simple pinging to a url and if it returns codes 301 or 302(redirection) to do some re-direction for that url. I think since my url needs ssl certificate, the return code is always 0, I used the below code and it always returns ([response statusCode] == 0)
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: myURL]]
NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (([response statusCode] == 301 ) || ([response statusCode] == 302)) {
//do some redirection for the app here
}
I had some research with Asynch API like:
connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
but still struggling identifying redirection even by ignoring ssl certificate.
Can anybody help me here? how can I just find out the the url needs to be redirected? I don't need to install certificate, i need only to ignore the ssl certificate and find out if I need redirection for that URL.
Any help would greatly appreciated.
I'm supporting for iOS 6 and above Thanks, Kam