UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

An SSL error has occurred and a secure connection to the server cannot be made

Forums > 100 Days of SwiftUI

Hi, I am on day 51, learning to load images and data from remote server. I am seeing the below error when submitting the order. I get the same error for loading images from "https://hws.dev/paul.jpg"

Task <64C43C96-B39A-401F-B56B-FB39299B99A0>.<3> finished with error [-1,200] Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, NSErrorPeerCertificateChainKey=(
    "<cert(0x131829800) s: reqres.in i: ca.goskope.com>",
    "<cert(0x13182a000) s: ca.goskope.com i: certadmin>",
    "<cert(0x13182a800) s: certadmin i: certadmin>"
), NSErrorClientCertificateStateKey=0, NSErrorFailingURLKey=https://reqres.in/api/cupcakes, NSErrorFailingURLStringKey=https://reqres.in/api/cupcakes, NSUnderlyingError=0x600000cf8750 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x600003320320>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=(
    "<cert(0x131829800) s: reqres.in i: ca.goskope.com>",
    "<cert(0x13182a000) s: ca.goskope.com i: certadmin>",
    "<cert(0x13182a800) s: certadmin i: certadmin>"
)}}, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalUploadTask <64C43C96-B39A-401F-B56B-FB39299B99A0>.<3>"
), _kCFStreamErrorCodeKey=-9802, _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <64C43C96-B39A-401F-B56B-FB39299B99A0>.<3>, NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x600003320320>, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made.}

sample code

func placeOrder() async {
        guard let encoded = try? JSONEncoder().encode(order) else {
            print("Failed to encode")
            return
        }

        let url = URL(string: "https://reqres.in/api/cupcakes")!
        var request = URLRequest(url: url)
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.httpMethod = "POST"

        do {
            let (data, _) = try await URLSession.shared.upload(for: request, from: encoded)

            let decodedOrder = try JSONDecoder().decode(Order.self, from: data)
            confirmationMessage = "Yuor order for \(decodedOrder)x\(Order.types[decodedOrder.type].lowercased()) cupcakes is on its way"
            showingConfirmation = true
        } catch {
            print("Check out failed: \(error.localizedDescription)")
        }
    }

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.