尝试登录Web服务:
let parameters: Parameters = [
"Password":password,
"Username":username
]
var headers:HTTPHeaders = commonHeaders()
headers["Content-Type"] = "application/json;charset=UTF-8"
Alamofire.request(url!, method:.post, parameters:parameters, headers:headers).responseJSON { response in
....
}
不知何故,我的参数最终在服务器端
"Username=xxx&Password=yyy"
哪里
{"Username":"xxx","Password":"yyy"}
是期待
这一定很简单,但我希望你能帮助我
添加您希望参数在请求中的编码类型,默认为.URLEncoding。所以,你的参数就像“Username = xxx&Password = yyy”(附加到url中)
将参数json encoding添加到您的请求中:
Alamofire.request(url!, method:.post, parameters:parameters, headers:headers, encoding: JSONEncoding.default)