[英]Reading data from response header of NSURLConnection
如何從服務器響應中發送的 header 讀取數據。 我正在使用 NSURLConnection 發送請求。
If the URL is an HTTP URL, then the NSURLResponse
that you receive in your connection's delegate's -connection:didReceiveResponse:
method (or via another method) will be an NSHTTPURLResponse
, which has an -allHeaderFields
method that lets you access the headers.
NSURLResponse* response = // the response, from somewhere
NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields];
// now query `headers` for the header you want
就我而言
NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
NSDictionary *headers = [response allHeaderFields];
好方法
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)[task response];
if ([httpResponse respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog(@"%@", [dictionary description]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.