AlamoFire 在使用 POST 调用时添加额外的字符串
AlamoFire adding extra string when using a POST call
当我使用 POST 使用 AlamoFire 时,其中一个字符串参数已向其中添加了字符?有什么想法吗?
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
这是参数的样子
address=Optional%28%22Adam%40yahoo.com%22%29&subscribed=1
如果我将电子邮件硬编码到
,这就是它的样子
let email = "adam@yahoo.com"
结果
address=adam%40yahoo.com&subscribed=1
问题是您的 email
被包装到一个可选的(可为空值)中。你可能想先打开它:
guard let email = emailText.text else {
// Handle the case where there is no email
return
}
...
当我使用 POST 使用 AlamoFire 时,其中一个字符串参数已向其中添加了字符?有什么想法吗?
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
这是参数的样子
address=Optional%28%22Adam%40yahoo.com%22%29&subscribed=1
如果我将电子邮件硬编码到
,这就是它的样子let email = "adam@yahoo.com"
结果
address=adam%40yahoo.com&subscribed=1
问题是您的 email
被包装到一个可选的(可为空值)中。你可能想先打开它:
guard let email = emailText.text else {
// Handle the case where there is no email
return
}
...