【发布时间】:2017-05-11 07:55:38
【问题描述】:
您好,我正在将 TRON 框架用于 iOS swift 项目,但在查找正确的文档以访问我的请求的响应标头时遇到了一些麻烦。
对于后端,我使用的是 Wordpress API v2,我想要获得的是 X-WP-Total 和 X-WP-TotalPages 标头。
这是我的请求函数:
let tron = TRON(baseURL: "http://example.com/wp-json/wp/v2")
func getFeed(){
let request: APIRequest<JSONFeed,JSONError> = tron.request("/posts")
request.perform(withSuccess: {(response) in
print("Ready to parse")
self.articlesFeatured = (response.articles! as NSArray) as? [listingObject]
DispatchQueue.main.async {
self.collectionListing.reloadData()
}
}, failure: {(err) in
print("Error ", err)
})
}
这些是用于请求的方法:
class JSONFeed: JSONDecodable{
var articles: [listingObject]? = []
required init(json: JSON) throws{
let array = json.array
for articleJson in array! {
let article = listingObject()
let title = articleJson["title"].stringValue
article.title = title
self.articles?.append(article)
}
}
}
class JSONError: JSONDecodable{
required init(json:JSON) throws{
print("Got an Error")
}
}
请求和方法解析工作正常,但我只得到响应值,但没有得到标头、状态码等附加信息。
【问题讨论】:
标签: ios json swift httprequest