ios - 如何修复用于 Apple 应用提交的 setAllowsAnyHTTPSCertificate 私有(private) api?

标签 ios objective-c nsurlrequest

这个问题在这里已经有了答案:





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

(13 个回答)


去年关闭。




我正在使用以下代码将用户登录信息发送到服务器,但 Apple 表示我正在使用私有(private) 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]];**

最佳答案

似乎有一个公共(public)API。

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

必须迟到但可能会有所帮助。

关于ios - 如何修复用于 Apple 应用提交的 setAllowsAnyHTTPSCertificate 私有(private) api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19276373/

相关文章:

curl - 来自 strip curl 的 NSUrlRequest

ios - UIWebView - 抛出什么 NSError?

ios - 使用 AFNetworking 2.0 的 SSL Pinning 允许 POST 请求,而不管使用的证书文件如何

ios - 如何在不触及其他依赖项的情况下删除特定的 pod

objective-c - iphone,如果可能的话,通过 UIImagePickerController 从照片库中选择多个文件

ios - 如何在cocos2d中填充纹理?

ios - 无法实例化名为 SCNView 的类

ios - 核心蓝牙 : CBPeripheral disconnects unknowingly and not getting any call to didDisconnectPeripheral

objective-c - Apple Headers 包含多个类别

swift 2.0,Alamofire : Set cookies in HTTP Post Request