Reading data from response header of NSURLConnection

后端 未结 2 1798
北恋
北恋 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:22

    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
    

提交回复
热议问题