2009-11-11 13 views
5

आईफोन द्वारा एसएसएल वेब सेवाओं से कनेक्ट करना सीखने का सबसे अच्छा प्रारंभिक बिंदु क्या है?आईफोन - एसएसएल कनेक्शन

अब तक मैंने एसओएपी आदि के माध्यम से http पर कुछ बुनियादी कनेक्शन किए हैं लेकिन मुझे https पर कोई अनुभव नहीं है। कोई भी अच्छा स्रोत, ट्यूटोरियल, संदर्भ शुरू करना, "nsurl का उपयोग करें ... वर्ग" की सराहना की जाती है

उत्तर

5

NSURLConnection डिफ़ॉल्ट रूप से SSL के साथ काम करता है और https साइट्स तक पहुंच सकता है। यूजर ट्रस्ट एसएसएल प्रमाणपत्र, here इस पर एक चर्चा है जो मुझे दिलचस्प लगता है, के बारे में समस्याएं प्रकट हो सकती हैं।

0

ASIHTTPRequest देखें। यह बहुत स्थिर, गैर-लीकी, उपयोग में आसान है और डाउनलोड फ़ाइल पुन: शुरू करने, प्रगति बार समर्थन इत्यादि जैसे उपहारों का एक गुच्छा शामिल है ... इसमें प्रमाणीकरण समर्थन

+0

CharlesProxy उपयोग कर सकते हैं एन्क्रिप्शन या कैसे के रूप में सुरक्षित के रूप में प्रमाणीकरण है क्या मैं इसे समझ सकता हूँ? धन्यवाद –

+0

यह एक बहुत पुराना उत्तर है, ASIHTTPRequest अब बनाए रखा नहीं जा रहा है। Https://github.com/AFNetworking/AFNetworking आज़माएं – coneybeare

1

मैं एक नमूना https क्लाइंट पोस्ट कर रहा हूं। यह अनदेखा करता है कि सर्वर प्रमाणपत्र मान्य नहीं है। सर्वर uritemplate के साथ एक webget विधि = उपयोगकर्ता नाम ({usercode})/पासवर्ड ({पासकोड}) है

आप अपने निवर्तमान संदेश की जाँच करने के

#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]; 
} 
संबंधित मुद्दे