Saturday, March 18, 2023
HomeiOS developmentswiftui - iOS app utilizing simulator studies "The certificates for this server...

swiftui – iOS app utilizing simulator studies “The certificates for this server is invalid.” error [-1202] Error Area=NSURLErrorDomain


Attempting to ship http put up request to the server utilizing iPhone14 Simulator. Code fragments is as follows:

var request = URLRequest(url: URL(string: "https://localhost:8443/process_file"))
  request.httpMethod = "POST"
var physique = Information()  // add physique information right here

let process = URLSession.shared.dataTask(with: request)
{ information, response, error in
    
    // Examine for errors
    if let error = error {
        completion(false, error)
        return
    }
    
    // Examine for a profitable response
    guard let httpResponse = response as? HTTPURLResponse, 
      (200...299).comprises(httpResponse.statusCode) else {
        completion(false, nil)
        return
    }
    
    // The request was profitable
    completion(true, nil)
  }

   // Begin the URLSession process
  process.resume()

I examined the server code utilizing Dart consumer sending put up request and it really works. Requests utilizing Postman additionally work. However Swift code generates following error. I attempted altering the certificates with none success.

2023-03-18 16:22:32.467056-0400 MyApp[3511:81183] Connection 1: default TLS Belief 
   analysis failed(-9807)
2023-03-18 16:22:32.467811-0400 MyApp[3511:81183] Connection 1: TLS Belief encountered 
   error 3:-9807
2023-03-18 16:22:32.468325-0400 MyApp[3511:81183] Connection 1: encountered 
   error(3:-9807)
2023-03-18 16:22:32.484207-0400 MyApp[3511:81183] Process <1C9997DB-4481-42FC-9698- 
   7C1CE90AF535>.<1> HTTP load failed, 0/0 bytes (error code: -1202 [3:-9807])
2023-03-18 16:22:32.524509-0400 MyApp[3511:81183] Process <1C9997DB-4481-42FC-9698- 
  7C1CE90AF535>.<1> completed with error [-1202] Error Area=NSURLErrorDomain 
  Code=-1202 "The certificates for this server is invalid. You may be connecting to 
  a server that's pretending to be “localhost” which might put your confidential 
  data in danger." UserInfo={NSLocalizedRecoverySuggestion=Would you wish to 
  connect with the server anyway?, _kCFStreamErrorDomainKey=3, 
NSErrorPeerCertificateChainKey=("<cert(0x7ff70501f200) s: localhost i: MY-CA>"), 
  NSErrorClientCertificateStateKey=0, 
   NSErrorFailingURLKey=https://localhost:8443/process_file, 
  NSErrorFailingURLStringKey=https://localhost:8443/process_file, 
  NSUnderlyingError=0x60000215d8f0 {Error Area=kCFErrorDomainCFNetwork Code=-1202 " 
  (null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, 
  kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x600001e35540>, 
 _kCFNetworkCFStreamSSLErrorOriginalValue=-9807, _kCFStreamErrorDomainKey=3, 
 _kCFStreamErrorCodeKey=-9807, kCFStreamPropertySSLPeerCertificates=(
     "<cert(0x7ff70501f200) s: localhost i: MY-CA>"
 )}}, _NSURLErrorRelatedURLSessionTaskErrorKey=(
     "LocalDataTask <1C9997DB-4481-42FC-9698-7C1CE90AF535>.<1>"
   ), _kCFStreamErrorCodeKey=-9807, 
  _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <1C9997DB-4481-42FC-9698- 
  7C1CE90AF535>.<1>, NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 
  0x600001e35540>, NSLocalizedDescription=The certificates for this server is invalid. 
 You may be connecting to a server that's pretending to be “localhost” which might 
 put your confidential data in danger.}
 Error sending file to server: The certificates for this server is invalid. You may 
  be connecting to a server that's pretending to be “localhost” which might put your 
 confidential data in danger.

Utilizing Xcode 14.2 on macOS 12.6.3

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments