【问题标题】:Url issue in swift 3.0 using Alamofire使用 Alamofire 的 swift 3.0 中的 URL 问题
【发布时间】:2017-04-05 08:44:38
【问题描述】:

我正在尝试发送短信,而我的带有数字的网址是“http://api.appname.my/sendSms.php?message=hello&phone=687985http://api.appname.my/sendSms.php?message=hello&phone=687985”,所以它为什么要删除其他数字。这是我的代码

  number = number + "60149041982"

    let url = "http://api.appname.my/sendSms.php?message=hello&phone=\(number)"

    Alamofire.request(url).response{ (responseObject) -> Void in
    print(responseObject)

    }

【问题讨论】:

  • 您可能需要转义“stackoverflow.com/questions/24551816/swift-encode-url
  • 实际上不需要api开发者添加这个来分隔数字。

标签: swift alamofire


【解决方案1】:

我认为您应该将< 字符编码为%3C

let urlString = "http://api.appname.my/sendSms.php?message=hello&phone=\(number)"
let url = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
print("Result: " + url!)

// Result: http://api.appname.my/sendSms.php?message=hello&phone=687985%3C6123488%3C60149041982

【讨论】:

    猜你喜欢
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多