简体   繁体   中英

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. How I can bypass check SSL certificate in iOS?

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.

Help me pls.

You need to allow Allow Arbitrary Loads . In your info.plist file, add this following entry

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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