gpt4 book ai didi

ios - 通过 SSL 请求 Web 服务

转载 作者:可可西里 更新时间:2023-11-01 03:13:36 25 4
gpt4 key购买 nike

我正在努力使用 https 请求 Web 服务。我收到这种错误:

An error occured : The certificate for this server is invalid. You might be connecting to a server that is pretending to be “SERVER_ADDRESS” which could put your confidential information at risk.

我没有使用 NSUrlConnectionDelegate。这是我的方法:

- (void)sendRequestWithUrl:(NSURL*)url block:(void (^)(NSDictionary *dict, NSError *error)) block{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
NSError* err = nil;
NSHTTPURLResponse* rsp = nil;
// Perform the request synchronously on this thread
NSData *rspData = [NSURLConnection sendSynchronousRequest:request returningResponse:&rsp error:&err];
if (rspData && err == nil) {
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:rspData options:NSJSONReadingMutableLeaves error:&err];
if(result) {
block(result, err);
} else {
block(nil, err);
}
}else{
DLog(@"Requesting URL: %@ An error occured : %@",url,[err localizedDescription]);
block(nil, err);
}
}

我该如何解决这个问题?

最佳答案

Apple 有一份技术说明很好地涵盖了这一点:

“技术说明 TN2232:HTTPS 服务器信任评估”

https://developer.apple.com/library/ios/#technotes/tn2232/_index.html

关于ios - 通过 SSL 请求 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14892009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com