如何修复用于 Apple 应用程序提交的 setAllowsAnyHTTPSCertificate 私有 api 使用? [英] How to fix setAllowsAnyHTTPSCertificate private api use for Apple app submission?
本文介绍了如何修复用于 Apple 应用程序提交的 setAllowsAnyHTTPSCertificate 私有 api 使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码将用户登录信息发送到服务器,但 Apple 表示我使用的是私有 API 并将拒绝该应用程序.我该如何解决?
I'm using the following code to send a user login to a server, but Apple says that I'm using a private API and will reject the app. How can I resolve this?
将替换为 [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]];**
推荐答案
似乎有一个公共 API.
There seems to be a public API for that.
如何使用 NSURLConnection 连接 SSL 以获得不受信任的证书?
必须迟到,但可能会有所帮助.
Must be late but might help.
这篇关于如何修复用于 Apple 应用程序提交的 setAllowsAnyHTTPSCertificate 私有 api 使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文