获取“位置"来自NSHTTPURLResponse的标头 [英] Getting "Location" header from NSHTTPURLResponse
问题描述
根本无法从响应中获取"Location"标头. Wireshark说我有一个:
Can't get "Location" header from response at all. Wireshark says that i've got one:
位置: http://*/index.html#0; sid = 865a84f0212a3a35d8e9d5f68398e535
Location: http://*/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;
}
在任何地方都没有位置.如何获得?我需要这个"sid"东西.
No location anywhere. How to get it? I need this "sid" thing.
推荐答案
NSHTTPURLResponse
是NSURLResponse
的子类,因此您可以要求它提供URL
.这将返回一个NSURL
对象,您可以从中获取URL组件,例如查询,参数字符串或片段.在您的情况下,您需要片段组件:
NSHTTPURLResponse
is a subclass of NSURLResponse
so you can just ask it for its URL
. This returns an NSURL
object from which you can get the URL components such as the query, parameter string or fragment. In your case you want the fragment component:
NSURL* url = [response URL];
NSString* fragment = [url fragment];
//fragment should be: 0;sid=865a84f0212a3a35d8e9d5f68398e535
这篇关于获取“位置"来自NSHTTPURLResponse的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!