Re: Getting HTTP response headers and status code
Re: Getting HTTP response headers and status code
- Subject: Re: Getting HTTP response headers and status code
- From: Dave Hersey <email@hidden>
- Date: Sun, 08 Feb 2004 13:24:52 -0500
Marco,
Check that the response is an HTTPURLResponse, and then just cast it.
Something like:
- (void) download: (NSURLDownload *) download
didReceiveResponse: (NSURLResponse *) response
{
if (response && ([response class] == [NSHTTPURLResponse class]))
{
NSDictionary *allHeaderFields;
int statusCode;
allHeaderFields = [(NSHTTPURLResponse *) response allHeaderFields];
statusCode = [allHeaderFields statusCode];
NSLog(@"statusCode = %d [\"%@\"]",
statusCode,
[allHeaderFields localizedStringForStatusCode: statusCode]);
}
else
{
// Not an NSHTTPURLResponse. I'm not sure why you would get here,
// since you're doing the requesting...
}
}
- dave
On 2/8/04 11:08 AM, "Marco Michieli" <email@hidden> wrote:
>
I need some help!
>
>
I would like to get the HTTP response headers and status code to a URL
>
load request.
>
>
I know that there are specific methods in NSHTTPURLResponse to do that:
>
>
allHeaderFields
>
+ localizedStringForStatusCode:
>
statusCode
>
>
But what I can't get is an instance of NSHTTPURLResponse: in fact when
>
I create the connection (that is a NSURLConnection) the delegate method:
>
>
connection:didReceiveResponse:
>
>
gives a response that is just a NSURLResponse and so I can't use such
>
methods.
>
>
>
Should be very easy, but I can't figure out how to get it work.
>
>
Any suggestion?
>
>
Thanks in advance
>
>
Marco
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.