我正在尝试将用户名,密码和grant_type值作为POST请求传递。
目前我的数组设置如下:
params = [
"grant_type": "password",
"password": password,
"username": user
]
当他们传递给我的alamofire POST请求时,我将它们注销,它们看起来像这样:
params = {
"grant_type" = password;
password = pas;
username = user;
}
pas
和user
是我输入的值。
这导致我的服务器出现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
}()
)
}
}