Reading data from response header of NSURLConnection

后端 未结 2 1802
北恋
北恋 2021-02-01 02:42

How can I read the data from the header sent by in the server response. I am using NSURLConnection to send the request.

2条回答
  •  攒了一身酷
    2021-02-01 03:27

    In my case

        NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
        NSDictionary *headers = [response allHeaderFields];
    

    Good Approach

        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)[task response];
        if ([httpResponse respondsToSelector:@selector(allHeaderFields)]) {
             NSDictionary *dictionary = [httpResponse allHeaderFields];
             NSLog(@"%@", [dictionary description]);
        }
    

提交回复
热议问题