Мне очень сложно войти на сайт HTTPS с ненастроенным SSL-сертификатом в swift. Я могу просмотреть страницу внутри моего UIWebView с помощью методов NSURLConnectionDelegate. Я могу автозарегистрироваться на этом веб-сайте, используя веб-браузер, например: URL-адрес: https://mywebsite.com:8003/home.html?session_id=sessionVariable. Но не из UIWebViewавтозапуск с HTTPS-сайтом с ненастроенным SSL-сертификатом в swift
Вот мой код внутри ViewDidLoad:
let websiteURL = "https://mywebsite.com:8003/home.html?session_id=\(Session_Id)"
print(websiteURL)
let url = NSURL (string: websiteURL)
let urlRequest = NSURLRequest(URL: url!)
let urlConnection:NSURLConnection = NSURLConnection(request: urlRequest, delegate: self)!
self.webviewInstance.loadRequest(urlRequest)
Мои делегируют функции
func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool{
print("canAuthenticateAgainstProtectionSpace method Returning True")
return true
}
func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge){
print("did autherntcationchallenge = \(challenge.protectionSpace.authenticationMethod)")
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
print("send credential Server Trust")
let credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)
challenge.sender!.useCredential(credential, forAuthenticationChallenge: challenge)
}else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPBasic{
print("send credential HTTP Basic")
let defaultCredentials: NSURLCredential = NSURLCredential(user: "username", password: "password", persistence:NSURLCredentialPersistence.ForSession)
challenge.sender!.useCredential(defaultCredentials, forAuthenticationChallenge: challenge)
}else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodNTLM{
print("send credential NTLM")
} else{
challenge.sender!.performDefaultHandlingForAuthenticationChallenge!(challenge)
}
}
Я aded изменения в моем файле Plist для ключей NSAppTransportSecurity, NSAllowsArbitraryLoads и т.д.
Я мог взаимодействовать с вызовами JSON с этим сервером. Но автоматический вход в систему из webView не работает. Пожалуйста, совет.