ios – The way to substitute session request with session add utilizing Alamofire in Swift?


I’ve a easy perform like this:

func carry out(
    request: NetworkRequest,
    technique: HTTPMethod,
    parameters: [String: Any]?,
    headers: [String: String],
    success: @escaping SuccessHandler,
    failure: @escaping FailureHandler
) { 

    // present NON WORKING resolution ❌

    let knowledge = JSONSerialization.knowledge(withJSONObject: parameters ?? [:])
    let sessionRequest = session.add(
        to: url(for: request),
        technique: technique,
        headers: HTTPHeaders(headers)

    // earlier WORKING resolution ✅

    let sessionRequest = session.request(
        url(for: request),
        technique: technique,
        parameters: parameters,
        encoding: JSONEncoding.default,
        headers: HTTPHeaders(headers)

    sessionRequest.responseJSON { response in 
        // do one thing with response

I would like to exchange request with add to have risk to trace progress of add. However my CURRENT resolution would not work and ends with 401. Why?