从NSURLConnection的响应头读取数据

Abh*_*nav 31 iphone cocoa-touch objective-c nsurlconnection

如何从服务器响应中发送的标头中读取数据.我正在使用NSURLConnection发送请求.

Joh*_*eek 77

如果URL是HTTP URL,那么NSURLResponse您在连接的委托-connection:didReceiveResponse:方法(或通过其他方法)中收到的URL 将是一个NSHTTPURLResponse,它具有一个-allHeaderFields允许您访问标头的方法.

NSURLResponse* response = // the response, from somewhere
NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields];
// now query `headers` for the header you want
Run Code Online (Sandbox Code Playgroud)