如何修复setAllowsAnyHTTPSCertificate私有api用于Apple应用程序提交?

时间:2013-10-09 15:33:11

标签: ios objective-c nsurlrequest

我正在使用以下代码将用户登录信息发送到服务器,但Apple表示我正在使用私有API并拒绝该应用。我该如何解决这个问题?

替换为[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]];**

1 个答案:

答案 0 :(得分:0)

似乎有一个公共API。

How to use NSURLConnection to connect with SSL for an untrusted cert?

必须迟到但可能有帮助。