0

I have referred to many posts with regard to the question I have. Below are the link I have referred,

The basic authentication in swift 5/XCode 12 version is failing. I get the below error in xcode,

2021-07-08 15:28:32.693835+0200 App[43664:810014] Connection 1: encountered error(3:-9816)
2021-07-08 15:33:33.042464+0200 App[43664:821863] Connection 2: received failure notification
2021-07-08 15:33:33.042685+0200 App[43664:821863] Connection 2: failed to connect 3:-9816, reason -1 

Below is the code I am using (I am using urlsession),

var mhUrlRequest = URLRequest(url: mhURL)
let userPasswordData = "username:password".data(using: .utf8)
let base64EncodedCredential = userPasswordData!.base64EncodedString(options: Data.Base64EncodingOptions.init(rawValue: 0))
let authString = "Basic \(base64EncodedCredential)"
mhUrlRequest.setValue(authString, forHTTPHeaderField: "Authorization")

I even tried the below code

let config = URLSessionConfiguration.default
config.httpAdditionalHeaders = ["Authorization" : authString]

But none of these seems to work for me.

James Z
  • 12,104
  • 10
  • 27
  • 43
Developer
  • 21
  • 1
  • 6
  • -9816 points to an ssl error. Are you using https? Is your certificate valid and trusted? Are you using strong ciphers? – Paulw11 Jul 08 '21 at 12:42
  • Yes.. It https. I have a valid certificate and it is trusted. The services are working fine in Postman. In Postman the basic auth is working but not in iOS – Developer Jul 08 '21 at 13:23
  • iOS ATS can be more strict on TLS than postman. The error isn't to do with basic authentication. You are getting a connection failure. Is your device time correct? – Paulw11 Jul 08 '21 at 13:34

0 Answers0