AlamoFire在使用POST调用时添加额外的字符串[重复]

问题描述 投票:-1回答:1

当我使用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
ios swift uilabel alamofire
1个回答
0
投票

问题是你的email被包装成一个可选的(可以为空的值)。您可能想先打开它:

guard let email = emailText.text else {
  // Handle the case where there is no email
  return
}
...
© www.soinside.com 2019 - 2024. All rights reserved.