根本无法从响应中获得“位置”标题。Wireshark说我有一个:
地点:/index.html#0;sid=865a84f0212a3a35d8e9d5f68398e535
但
NSHTTPURLResponse *hr = (NSHTTPURLResponse*)response;
NSDictionary *dict = [hr allHeaderFields];
NSLog(@"HEADERS : %@",[dict description]);产生这种情况:
HEADERS : {
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "text/html";
Date = "Thu, 25 Mar 2010 08:12:08 GMT";
"Last-Modified" = "Sat, 29 Nov 2008 15:50:54 GMT";
Server = "nginx/0.7.59";
"Transfer-Encoding" = Identity;
}任何地方都找不到。怎么弄到?我需要这个“希德”的东西。
发布于 2010-03-25 08:46:47
NSHTTPURLResponse是NSURLResponse的一个子类,所以您只需向它请求它的URL。这将返回一个NSURL对象,您可以从该对象获取查询、参数字符串或片段等URL组件。在您的示例中,您需要片段组件:
NSURL* url = [response URL];
NSString* fragment = [url fragment];
//fragment should be: 0;sid=865a84f0212a3a35d8e9d5f68398e535发布于 2015-10-19 11:46:04
他认为,用如何在Swift中访问Location头的示例来补充@Rob的回答可能会有所帮助。如上面所示,"Location“是一个HTTP响应头字段,因此在Swift中可以这样做:
if let location = response.allHeaderFields["Location"] as? String
{
NSLog("Location \(location)")
}其中response的类型为NSHTTPURLResponse。见NSHTTPURLResponse类引用。
https://stackoverflow.com/questions/2513916
复制相似问题