ios - 附加路径组件 : does not do percentage encoding resulting in load failures in swift 3

标签 ios url swift3 xcode8.2

在 swift 3 中,我使用 alamofire 进行网络调用。为此,我将 Base URL 附加到字符串中。因为我得到的响应为零。请找到下面的代码:

public var baseURL: URL { return URL(string: "http://138.112.175.138:3300/api")! }

    public var path: String {
    switch self {

    case .carsSearch:
      return "/cars/display?model=1"

    default:
      return ""
    }
  }

用于附加此:

    public func url() -> String {
    return self.baseURL.appendingPathComponent(self.path).absoluteString
  }

但我得到的输出为:

<强> http://138.112.175.138:3300/api/cars/display%3Fmodel=1

因此我的回复为零。如何解决这个问题?

最佳答案

尝试删除当前编码:

public func url() -> String {
    return self.baseURL.appendingPathComponent(self.path).absoluteString.removingPercentEncoding
  }

关于ios - 附加路径组件 : does not do percentage encoding resulting in load failures in swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45089629/

相关文章:

ubuntu - Ubuntu 上的 Swift : use of undeclared type 'NSFileHandle'

ios - 我的 collectionView 中的页 footer 分出现问题

ios - 忽略存储库中的 CocoaPods 库

ios - 在 iOS 应用程序中从 Firebase 获取发送推送通知的历史记录

java - 通过HttpURLConnection访问HTTP网站的问题

node.js - 如何检查应用程序中是否存在 req.url 路径?

python - 断言python Appium中的特殊字符

java - 使用 RestEasy 找不到该网址的网页

swift - 在 Swift 3 中使用 SWXMLHash 反序列化一个类

swift3 - 如何使用字典将字符串数组存储到 Realm 实例中?