Swift AlamoFire 5 won't execute Request

Viewed 198

My problem is, when I execute the request it will happen nothing.

What I made:

I made an Api with .net core Api on a another PC and now I want to make a IOS App, that has access to the Api. (The API works I tested it with swagger and Insomnia) On the IOS app I made a put request with AlamoFire. And when I execute the request it's happening nothing. I watched the Network with Wireshark and there comes Nothing too.

When I Debug, it will step through the request Methode, but it goes nothing out to the API. And there are no errors.

// buttonClick will call this Methode
func requst() {
        
        // testing parameters
        let params: Parameters = [
            "nfcId": 1,
            "date" : "2021-04-12T09:47:12.053Z"
        ]
        
        //
        session.request("http://MyAPI/api/Guard/AddGuard", method: .put, parameters: params, headers: nil).validate(statusCode: 200 ..< 299)
        
    }

I made an own Session wehere I pinned a certificate

    private let certificates = [
        "https://MyAPI:5001":
            PinnedCertificatesTrustEvaluator(certificates: [Certificates.certificate], acceptSelfSignedCertificates: false, performDefaultValidation: true, validateHost: true)
    ]
    
    private let session: Session
    
    init(allHostsMustBeEvaluated: Bool) {
        
        let serverTrustPolicy = ServerTrustManager(allHostsMustBeEvaluated: allHostsMustBeEvaluated, evaluators: certificates)
        let config = URLSessionConfiguration.af.default
        session = Session(configuration: config, serverTrustManager: serverTrustPolicy)
    }
1 Answers

You haven't attached a response handler or called resume(), so no, the request isn't going to do anything. Adding something like responseDecodable will start the request automatically.

Related