Lectura de datos del encabezado de respuesta de NSURLConnection
Cómo puedo leer los datos del encabezado enviado por en la respuesta del servidor. Estoy usando NSURLConnection para enviar la solicitud.
30
2 answers
Si la URL es una URL HTTP, entonces el NSURLResponse
que recibe en el método -connection:didReceiveResponse:
del delegado de su conexión (o a través de otro método) será un NSHTTPURLResponse
, que tiene un -allHeaderFields
método que le permite acceder a los encabezados.
NSURLResponse* response = // the response, from somewhere
NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields];
// now query `headers` for the header you want
73
Author: John Calsbeek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-08 00:38:49
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-08 00:38:49
En mi caso
NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
NSDictionary *headers = [response allHeaderFields];
Buen enfoque
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)[task response];
if ([httpResponse respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog(@"%@", [dictionary description]);
}
2
Author: Ali,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-24 08:26:22
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-24 08:26:22