Alamofire请求声明参数和方法的额外参数

时间:2017-01-05 11:56:13

标签: swift encoding swift3 alamofire url-encoding

从swift 2.3更新到3后,我的Router类中的NSMutableURLRequest出现以下问题:

    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
}

错误表明类型参数编码没有成员URL。

在我的vc中,我将此方法称为:Alamofire.request(Router.controlRequest(a:a,b:b,c:c))                     .responseJSON

查看迁移指南,我真的不确定如何构建变更...

我是否将VC中的呼叫更改为包含编码,还是可以在我的路由器类中处理?

编辑:

在我的vc中,我尝试调用这样的方法:

 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)

然后我得到错误,在调用参数和方法

时还有一个额外的参数

0 个答案:

没有答案