简体   繁体   English

iOS https /主机没有SSL证书

[英]iOS https / Host dont't has SSL certificate

I ran into a problem and needs help. 我遇到了问题,需要帮助。 I send a request to the server via HTTPS but server don't has SSL certificate. 我通过HTTPS向服务器发送了一个请求,但是服务器没有SSL证书。 How I can bypass check SSL certificate in iOS? 如何绕过iOS中的SSL证书检查?

My Code: 我的代码:

let loginString = String(format: "Login:Pass")
let loginData = loginString.data(using: String.Encoding.utf8)!
let base64LoginString = loginData.base64EncodedString()

let headers = [
    "content-type": "application/xml",
    "authorization": "Basic \(base64LoginString)"
]

let postData = NSData(data: "BODY".data(using: String.Encoding.utf8)!)

let request = NSMutableURLRequest(url: URL(string: "IP")!, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)

request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

var session = URLSession.shared
session = URLSession(configuration: URLSessionConfiguration.default, delegate: self as? URLSessionDelegate, delegateQueue: nil)
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in

    if (error != nil) {
        print(error.debugDescription)
    } else {
        let responseData = String(data: data!, encoding: String.Encoding.utf8)!
        print(responseData)
    }
})

dataTask.resume()

My Error: 我的错误:

The certificate for this server is invalid. 该服务器的证书无效。 You might be connecting to a server that is pretending to be “IP” which could put your confidential information at risk. 您可能正在连接到假装为“ IP”的服务器,这可能会使您的机密信息受到威胁。

Help me pls. 请帮助我。

You need to allow Allow Arbitrary Loads . 您需要允许Allow Arbitrary Loads In your info.plist file, add this following entry 在您的info.plist文件中,添加以下条目

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM