Alamofire request stating extra argument for both parameters and method

。_饼干妹妹 提交于 2019-12-10 23:02:23

问题


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

来源:https://stackoverflow.com/questions/41484477/alamofire-request-stating-extra-argument-for-both-parameters-and-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!