Alamofire request stating extra argument for both

2019-07-10 05:01发布

问题:

After updating from swift 2.3 to 3, I have the following issue with NSMutableURLRequest in my Router class:

    var URLRequest: NSMutableURLRequest {
    let URL = Foundation.URL(string: Router.baseURLString)!
    let mutableURLRequest = NSMutableURLRequest(url: URL.appendingPathComponent(path))
    mutableURLRequest.httpMethod = method.rawValue

    switch self {
    case .controlRequest(let a, let b, let c):
        let req : RegisterServer.Request = RegisterServer.Request()
        req.a = a
        req.b = b
        req.c = c

        let reqAsJsonStr = String(describing: JSON(req))
        //let encryptedReqStr = encryptForPost(reqAsJsonStr)
        let parameters : [String : String] = [
            "d" : reqAsJsonStr.toBase64()!
        ]

        return Alamofire.ParameterEncoding.URL.encode(mutableURLRequest, parameters: parameters).0
    //other cases
}

The error states that type parameter encoding has no member URL.

In my vc, I call this method like: Alamofire.request(Router.controlRequest(a: a, b: b, c: c)) .responseJSON

Looking at the migration guide, I am really unsure how to structure the change...

Do I change the call in my VC to include encoding or can it be handled in my router class?

EDIT:

In my vc, I tried calling the method like so:

 let req : RegisterServer.Request = RegisterServer.Request()
        req.a = a
        req.b = b
        req.c = c

        let reqAsJsonStr = String(describing: JSON(req))
        //let encryptedReqStr = encryptForPost(reqAsJsonStr)
        let parameters : [String : String] = [
            "d" : reqAsJsonStr.toBase64()!
        ]

 Alamofire.request(Router.controlRequest.path, method: .post, parameters: parameters, encoding: URLEncoding.default)

but then I get the error that there is an additional argument in call for both parameters and method