2013-10-09 12 views
1

我正在使用下面的代碼發送用戶登錄到服務器,但蘋果表示我使用私人API並將拒絕該應用程序。我該如何解決這個問題?如何解決setAllowsAnyHTTPSCertificate私人API用於Apple應用程序提交?

會替換[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];[request setHTTPMethod:@"POST"]; 就夠了嗎?

@interface NSURLRequest (DummyInterface) 
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host; 
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host; 
@end 

和我的登錄代碼:

  // token url 
      NSURL *url=[NSURL URLWithString:@"http://xxxxxxxx.com/api/token"]; 

      NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

      NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 

      NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
      [request setURL:url]; 
      [request setHTTPMethod:@"POST"]; 
      [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
      [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; 
      [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
      [request setHTTPBody:postData]; 

      NSLog(@"url is %@",url), 
      NSLog(@"request is %@",request), 


      **[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];** 
+2

可能的重複[如何使用NSURLConnection與SSL連接的不可信的證書?](http://stackoverflow.com/questions/933331/how-to-use-nsurlconnection-to-connect-with-ssl- for-an-untrusted-cert) – Bastian

+0

非常感謝。快速的東西,但會取代[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]]; [request setHTTPMethod:@「POST」];工作?我已經嘗試過了,它會將用戶登錄到等等......似乎工作。只是想知道蘋果會不會好 – user2588945

回答

相關問題