Reputation: 3
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.
Upvotes: 0
Views: 1451
Reputation: 25280
You need to allow Allow Arbitrary Loads
. In your info.plist file, add this following entry
Upvotes: 1