Alamofire参数中带下划线的奇怪错误

时间:2015-10-16 16:10:47

标签: ios swift alamofire

我正在尝试将用户名,密码和grant_type值作为POST请求传递。

目前我的数组设置如下:

params = [
 "grant_type": "password",
 "password": password,
 "username": user
]

当他们传递给我的alamofire POST请求时,我将它们注销,它们看起来像这样:

params = {
"grant_type" = password;
password = pas;
username = user;
}

pasuser是我输入的值。

这导致我的服务器出现400错误,我怀疑是因为grant_type由于某种原因被读作引号?

这是我发出POST请求的方式:

networking.makePostRequest(Constants.loginUrl, params: loginParams) { response, json in
        print("response")
        print(response)
        print("json")
        print(json)

    }

实际的POST请求函数如下所示:

unc makePostRequest(url : String, params : AnyObject, completionHandler: (httpResponse: NSHTTPURLResponse, responseObject:JSON?) -> ())  -> Request? {


    print("params = \(params)")
    return Alamofire.request(.POST, url, parameters: params as? [String : AnyObject], encoding: .JSON)


        .responseJSON { _, response, result in completionHandler(

            httpResponse: response!,
            responseObject:
            {
                var json: JSON?

                switch result {
                case .Success:



                    if let data: AnyObject = result.data
                    {

                        json = JSON(data)
                    }

                    return json

                case .Failure(_, let error):
                    print(error)
                }

                 return json

                }()
            )
    }
}

0 个答案:

没有答案