如何获取Alamofire get-request的位置标题?

时间:2017-10-01 10:06:45

标签: ios swift alamofire

我的iOS应用程序使用get-method将搜索发送到服务器,如果搜索仅匹配一个对象,则该服务器应使用location-header进行响应。我从未看到使用location-header的响应,而是直接在响应中获得匹配的对象。

Alamofire在获取位置标头时会自动下载资源吗?我需要首先获取location-header,因为我需要在我的应用程序中使用该文件的名称。

当调用返回时,这是response.allHeaderFields的内容:

[AnyHashable(" Content-Type"):application / luetus,AnyHashable(" Content-Length"):215271,AnyHashable(" Keep-Alive" ):timeout = 15,max = 100,AnyHashable(" Connection"):Keep-Alive,AnyHashable(" Etag"):" 348e7-55a74cd064680",AnyHashable (" Last-Modified"):Sun,2017年10月1日04:36:26 GMT,AnyHashable(" Accept-Ranges"):bytes,AnyHashable(" Server" ;):Apache / 2.2.12(Linux / SUSE),AnyHashable(" Date"):Sun,2017年10月1日11:19:30 GMT]

如您所见,没有位置标题。

1 个答案:

答案 0 :(得分:1)

如果您想访问标题字段,Alamofire请求中的response应该有标题,您可以通过以下方式访问:

response.response?.allHeaderFields