Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 2.24 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. HTTPS request with Cocoa/objective-C
  2. -(void)Authenticate
  3. {
  4.     self.responseData = [NSMutableData data];
  5.     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://10.84.4.2:8444/fish-mobile/GetPIN.jsp?MSISDN=12345"]];
  6.     //NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  7.  
  8.     [[NSURLConnection alloc] initWithRequest:request delegate:self];
  9. }
  10.  
  11. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
  12.     [responseData setLength:0];
  13.  
  14. }
  15. - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
  16.     return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
  17. }
  18.  
  19.     - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:       (NSURLAuthenticationChallenge *)challenge {
  20.  
  21.     [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
  22.  
  23.     [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
  24. }
  25.  
  26.     - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
  27.     [responseData appendData:data];
  28. }
  29.  
  30.     - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
  31.     self.responseData = nil;
  32. }
  33.  
  34.  
  35. - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  36.  
  37.       NSString *responseString = [[NSString alloc] initWithData:responseData       encoding:NSUTF8StringEncoding];
  38.  
  39.  
  40.     NSLog(@"%@", responseString);
  41.  
  42.     }
  43.        
  44. [responseData setLength:0];
  45.        
  46. [responseData appendData:data];
  47.        
  48. -(void) testme: (NSString *) link{
  49. NSURL * url = [NSURL URLWithString:link];
  50. NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];
  51. [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  52. [request setHTTPMethod:@"GET"];
  53. [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
  54.        
  55. - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
  56. return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];