大家下午好,新手在这里试图学习
Swift / Alamofire.我已经挣扎了将近两天,我已准备好继续前进了.
我的网址似乎已更正,但我在发出请求时收到错误消息.在查看Xcode调试日志时,看起来我的单引号在发送请求时被转义.
let owner : String = "me@corp.local" func getDeploymentsByOwner(token: String,owner: String,success: @escaping (JSON) -> Void,failure: @escaping (Error) -> Void) { let headers = [ "Authorization": "Bearer \(token)",] print(owner) let url = "https://corp.local?$filter=owners/ref eq '\(owner)'" // created URL is https://corp.local?$filter=owners/ref eq 'me@corp.local' Alamofire.request(url,method: .get,encoding: URLEncoding.queryString,headers: headers).responseJSON { (responSEObject) -> Void in if responSEObject.result.isSuccess { let resJSON = JSON(responSEObject.result.value!) success(resJSON) } if responSEObject.result.isFailure { let error = responSEObject.result.error print(error) failure(error!) } }
Optional(Alamofire.AFError.invalidURL("https//:corp.local?$filter=owners/ref eq \'me@corp.local\'")) invalidURL(https://corp.local?$filter=owners/ref eq \'me@corp.local\'")
我可以获得没有$filter的所有项目,因此只要省略过滤器,请求就会起作用.
// Postman使用生成的URL,但带有反斜杠()的URL不会