您好我尝试将Alamofire用于我的项目,但错误就出来了。 这是我的请求代码 // Google测试
Alamofire.request("http://google.com").responseString{
response in
debugPrint(response)
}.session.invalidateAndCancel()
结果]:FAILURE:错误域= NSURLErrorDomain代码= -999"取消"
UserInfo = {NSErrorFailingURLKey = http://google.com/,
NSLocalizedDescription =已取消,
NSErrorFailingURLStringKey = http://google.com/}
//自己进行服务器测试
Alamofire.request("https://10.68.24.127:4533").responseString{
response in
debugPrint(response)
}.session.invalidateAndCancel()
相同的结果
class NetworkManager {
var manager: SessionManager?
init() {
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"https://10.68.24.127:4533" : .disableEvaluation
]
let configuration = URLSessionConfiguration.default
manager = Alamofire.SessionManager(
configuration: configuration,
serverTrustPolicyManager :ServerTrustPolicyManager(policies: serverTrustPolicies)
)
}
}
我将NSAllowsArbitraryLoads设置为true和NSExceptionDomains。
问题出在哪里?
答案 0 :(得分:0)
请查看Alamofire app-transport-security
中的此文档尝试在.plist文件中添加以下内容
<key>NSAppTransportSecurity</key><dict>
<key>NSExceptionDomains</key>
<dict>
<key>url.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
答案 1 :(得分:0)
您很可能应该检查是否存在身份验证质询委托方法的实现,并检查其是否调用NSURLSessionAuthChallengeCancelAuthenticationChallenge。
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler