Siesta iOS POST请求错误输出“不支持的URL”

时间:2015-10-15 11:52:52

标签: ios swift rest swift2 siesta-swift

我遇到了Siesta - 一个iOS REST客户端框架https://bustoutsolutions.github.io/siesta/

以下是对REST API服务器的POST请求的简单示例,该请求因“不支持的URL”错误而失败。那里有没有人有过Siesta的经历,可能出现什么问题?

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"

1 个答案:

答案 0 :(得分:4)

Service.resource(url:)方法 - 标有url:参数的方法 - 需要完整的网址。看起来您需要Service.resource(_:),它采用相对于服务基本URL的路径。

尝试:

api.resource("users/login")