我遇到了Siesta - 一个iOS REST客户端框架https://bustoutsolutions.github.io/siesta/。
以下是对REST API服务器的POST请求的简单示例,该请求因“不支持的URL”错误而失败。那里有没有人有过Siesta的经历,可能出现什么问题?
let api = Service(base: "http://myapidomain.net/rest")
enabledLogCategories = LogCategory.all
let parameters = ["username": "username", "password": "password"]
api.resource(url: "users/login").request(.POST, json: NSDictionary(dictionary: parameters)).success { data in
debugPrint("success logging in")
}.failure { error in
debugPrint("failed to log in")
}
[Siesta:Configuration] Computing configuration for Siesta.Resource(users/login)[]
[Siesta:Configuration] Applying config 0 [Siesta default response transformers] to Siesta.Resource(users/login)[]
[Siesta:NetworkDetails] Request:
headers: (1)
Content-Type: application/json
[Siesta:Network] POST users/login
[Siesta:Network] – ← POST users/login
[Siesta:NetworkDetails] Raw response headers: –
[Siesta:NetworkDetails] Raw response body: 0 bytes
[Siesta:NetworkDetails] Response after transformer pipeline: (new data)
Failure
userMessage: "unsupported URL"
nsError: "unsupported URL"
"failed to log in"
答案 0 :(得分:4)
Service.resource(url:)
方法 - 标有url:
参数的方法 - 需要完整的网址。看起来您需要Service.resource(_:)
,它采用相对于服务基本URL的路径。
尝试:
api.resource("users/login")