【问题标题】:How to fix setAllowsAnyHTTPSCertificate private api use for Apple app submission? [duplicate]如何修复 setAllowsAnyHTTPSCertificate 私有 api 用于 Apple 应用提交? [复制]
【发布时间】:2013-10-17 01:38:30
【问题描述】:

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

【问题讨论】:

  • 谢谢,太好了。快速的事情 - 将替换为 [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]]; [请求 setHTTPMethod:@"POST"];工作?我已经尝试过了,它让用户登录等等......似乎工作。只是想知道苹果是否可以
  • 我不明白你关于replacing above的问题。换成什么? :) setAllowsAnyHTTPSCertificate: 是私有的 - 你想用什么替换它? :) [检查重复的帖子]
  • 链接的帖子应该会引导您找到使用 URLConnection 或 URLSession 的方法。而且你还没有分享你使用的 api 但是.....stackoverflow.com/questions/19507207/…

标签: ios objective-c nsurlrequest


【解决方案1】:

似乎有一个公共 API。

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-03-21
  • 2020-01-05
  • 1970-01-01
  • 2012-02-08
  • 1970-01-01
  • 1970-01-01
  • 2015-04-25
  • 1970-01-01
相关资源
最近更新 更多