2009-11-11 9 views
5

¿Cuál es el mejor punto de partida para aprender a conectarse a servicios web ssl por iphone?iPhone - Conexión SSL

Hasta ahora hice algunas conexiones básicas sobre http a través de SOAP, etc., pero no tengo experiencia en https. Se aprecia cualquier buena fuente, tutoriales, referencias de partida, "use nsurl ... class" s

Respuesta

5

NSURLConnection funciona de manera predeterminada con SSL y puede acceder a los sitios https. Pueden aparecer problemas con respecto a dejar que el usuario confíe en los certificados SSL, here es una discusión sobre esto que he encontrado interesante.

0

Consulte ASIHTTPRequest. Es muy estable, sin fugas, fácil de usar e incluye muchos extras como descargar archivos, soporte de barra de progreso, etc. También tiene soporte de autenticación

+0

es la autenticación tan seguro como el cifrado o cómo puedo entender esto? Gracias –

+0

Esta es una respuesta muy antigua, ASIHTTPRequest ya no se mantiene. Pruebe https://github.com/AFNetworking/AFNetworking – coneybeare

1

Estoy publicando un ejemplo de cliente https. ignora si el certificado del servidor no es válido. el servidor tiene un método WebGet con UriTemplate = nombre de usuario ({código de usuario})/contraseña ({contraseña})

puede utilizar CharlesProxy para comprobar su mensaje de salida

#import "Hello_SOAPViewController.h" 
@interface NSURLRequest (withHttpsCertificates) 
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host; 
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host; 
@end 

@implementation Hello_SOAPViewController 


NSMutableData *webData; 

- (void)viewDidLoad { 

////////////////////////////////////////////////// 

//Web Service Call 

////////////////////////////////////////////////// 

    NSURL *url = [NSURL URLWithString:@"https://192.168.1.105/HelloService/Service.svc/username(user)/password(xxx)"];       

    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0]; 
    [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]]; 

    [theRequest addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];  

    [theRequest setHTTPMethod:@"GET"];  
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if(theConnection) { 
     webData = [[NSMutableData data] retain]; 
    } 
    else { 
     NSLog(@"theConnection is NULL"); 
    } 

} 



-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [webData setLength: 0]; 
} 
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [webData appendData:data]; 
} 
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 

    NSLog(@"ERROR with theConnection:%@",[error description]); 
    if ([error code] == -1001){//isEqualToString:@"timed out"]) { 
     UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Server Unresponsive" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; 
     [alertView show]; 

    }else{ 
     UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Check your internet connection " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; 
     [alertView show]; 
    } 


    [connection release]; 
    [webData release]; 
} 
-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"DONE. Received Bytes: %d", [webData length]); 

    /////////////////////// 
    //Process Your Data here: 






    /////////////////////// 

    [connection release]; 
    [webData release]; 

} 


- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 

    [super dealloc]; 
} 
Cuestiones relacionadas