处理API调用时,在调用中获取Extra参数'method',

时间:2018-08-03 01:55:19

标签: swift alamofire

现在,我使用Alamofire最新版本4.7.3,并使用swift 4.1,我收到错误获取Extra参数,我不知道发生了什么事情

func serviceHandling(){
    let url : String = "http://1.1.11.15:8080/f/api/getLoginDetails"
    var params: NSDictionary = ["userName" : "test1234" , "password":"test1234" ,"gcmRegistrationId":"test","deviceType":"iPhone"]

    Alamofire.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: nil).responseJSON
        { (response:DataResponse<Any>) in
    }
}

enter image description here

1 个答案:

答案 0 :(得分:1)

您已在此行将params声明为NSDictionary

var params: NSDictionary = ["userName" : "test1234" , "password":"test1234" ,"gcmRegistrationId":"test","deviceType":"iPhone"]

Alamofire请求要求使用Parameter类型的参数,而实际上是[String: Any]类型的参数。您要做的就是用这种类型声明您的参数

var params: [String: Any] = ["userName" : "test1234" , "password":"test1234" ,"gcmRegistrationId":"test","deviceType":"iPhone"]