看到回复:
headers { "Content-Length" = 95; "Content-Type" = "application/Json; charset=utf-8"; Date = "Fri,15 Apr 2016 08:01:58 GMT"; Server = "Apache/2.4.18 (Unix)"; "X-Dem-Auth" = null; "X-Powered-By" = Express;如果响应是NShttpURLResponse的类型,则可以从response.allheaderFIElds获取标头
正如苹果文档所说:
A dictionary containing all the http header fIElds received as part of the server’s response. By examining this dictionary clIEnts can see the “raw” header information returned by the http server.
The keys in this dictionary are the header fIEld names,as received from the server. See RFC 2616 for a List of commonly used http header fIElds.
因此,要获得响应标头中的X-Dem-Auth,您可以通过以下方式访问它:
if let httpResponse = response as? NShttpURLResponse { if let xDemAuth = httpResponse.allheaderFIElds["X-Dem-Auth"] as? String { // use X-Dem-Auth here }}
UPDATE
由于Evan R的评论而更新
if let httpResponse = response as? httpURLResponse { if let xDemAuth = httpResponse.allheaderFIElds["X-Dem-Auth"] as? String { // use X-Dem-Auth here }}总结
以上是内存溢出为你收集整理的从swift中的请求响应中获取头数据全部内容,希望文章能够帮你解决从swift中的请求响应中获取头数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)