当我尝试从内部 Web 服务器获取 json 时,我需要应对挑战。我从上一个问题中遵循了这一点。这是我的代码
let defaultManager: Alamofire.SessionManager = {
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"myhttpsinternaldomain.org": .disableEvaluation
]
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
return Alamofire.SessionManager(
configuration: configuration,
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)
}()
let url = URL(string: urlString)
let username = "user"
let password = "password"
let header = ["user": username, "password": password]
defaultManager.request(url!, method: .get, headers: header).responseJSON { response in
switch response.result {
case .success(let value):
let json = JSON(value)
print("JSON: \(json)")
case .failure(let error):
print(error)
}
}
这是我收到的错误
错误域=NSURLErrorDomain 代码=-999 “取消” UserInfo={NSErrorFailingURLKey= https://myhttpsinternaldomain.org , NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey= https://myhttpsinternaldomain.org }
我找到了这个,但我的项目中没有令牌。我只想使用用户名和密码或忽略挑战
请任何帮助