Я столкнулся с трудностями при входе на сайт HTTPS с ненадежным SSL-сертификатом в быстром режиме. Я могу просмотреть страницу внутри своего UIWebView, используя методы NSURLConnectionDelegate. Я могу автоматически войти на этот веб-сайт с помощью веб-браузера, например: URL - https://mywebsite.com:8003/home.html?session_id=sessionVariable . Но не из UIWEbView
Вот мой код внутри 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)
}
}
Я добавил изменения в свой файл plist для ключей NSAppTransportSecurity , NSAllowsArbitraryLoads и т. д.
Я мог бы взаимодействовать с вызовами JSON с этим сервером. Но автоматический вход из webView не работает. Пожалуйста посоветуй.