gpt4 book ai didi

ios - 如何使用 AFNetworking 允许 https 连接?

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

我设置了 AFNetworking,但它不接受 https 网址。如何让 AFNEtworking 通过 ssl 连接。

我有以下代码:

  NSMutableURLRequest *apiRequest =
[self multipartFormRequestWithMethod:@"POST"
path: pathstr
parameters: params
constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
{
//TODO: attach file if needed
}];



AFJSONRequestOperation* operation = [[AFJSONRequestOperation alloc] initWithRequest: apiRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//success!
completionBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//failure :(

NSLog(@"%@", error);
completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
}];

[operation start];

最佳答案

operation.securityPolicy.allowInvalidCertificates = YES;

这段代码非常重要。如果你不添加这个你会得到一个错误。

关于ios - 如何使用 AFNetworking 允许 https 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14900572/

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