1

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

Cam
  • 275
  • 6
  • 24
  • I found an API: - (NSURLRequest *)connection: (NSURLConnection *)inConnection willSendRequest: (NSURLRequest *)inRequest redirectResponse: (NSURLResponse *)inRedirectResponse; Not sure it will work for my cases, I'll give a try. – Cam Nov 13 '13 at 21:33
  • Can I assume that if [response statusCode] == 0, I have always SSL certificate issue? if yes,I guess I can call asyn nsurlconnection and with redirect delegate method above, and can set the url to a new one? – Cam Nov 13 '13 at 21:55

0 Answers0