AlamoFire在使用POST调用时添加额外的字符串

时间:2019-03-05 01:20:50

标签: ios swift uilabel alamofire

当我在使用AlamoFire的POST时,其中一个String参数添加了字符吗?有想法吗?

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

1 个答案:

答案 0 :(得分:0)

问题是您的email被包装到一个可选的(空值)中。您可能要先将其拆开:

guard let email = emailText.text else {
  // Handle the case where there is no email
  return
}
...