这个问题在这里已有答案:
当我使用AlamoFire使用POST时,其中一个String param添加了字符?任何的想法?
let email = emailText.text
Alamofire.request("https://xxxx", method: .post, parameters: ["subscribed": true,"address": email],encoding: URLEncoding.httpBody, headers: headers).validate()
.log().responseJSON {
response in
这就是params的样子
address=Optional%28%22Adam%40yahoo.com%22%29&subscribed=1
如果我硬编码电子邮件,这就是它的样子
let email = "[email protected]"
结果
address=adam%40yahoo.com&subscribed=1
问题是你的email
被包装成一个可选的(可以为空的值)。您可能想先打开它:
guard let email = emailText.text else {
// Handle the case where there is no email
return
}
...