Re: HEAD request using NSURLConnection
Re: HEAD request using NSURLConnection
- Subject: Re: HEAD request using NSURLConnection
- From: Patrick Machielse <email@hidden>
- Date: Fri, 23 Jan 2004 13:42:35 +0100
op 23-01-2004 07:00 schreef Daniel Miao:
>
I have been trying to get the content length of a URL using an HTTP
>
HEAD request.
>
>
Here is my code snippet:
>
>
NSMutableURLRequest *request = [NSMutableURLRequest
>
requestWithURL:aURL
>
cachePolicy:NSURLRequestReloadIgnoringCacheData
>
timeoutInterval:30.0];
>
>
[request setHTTPMethod:@"HEAD"];
>
>
NSURLResponse *response = [[NSURLResponse alloc] init];
>
NSError *error = [[NSError alloc] init];
>
>
[NSURLConnection sendSynchronousRequest:request
>
returningResponse:&response error:&error];
Daniel,
I don't recognize the symptoms you describe, but since this is a synchronous
call it will wait until all data is in.
I also want to point out a memory leak in your code. In my experience
sendSynchronousRequest::: returns response and error as autoreleased
objects. You only have to pass 'adresses of pointers to NSURLResponse and
NSError'. So:
NSError *error;
NSURLResponse *response;
NSData *dataReply;
dataReply = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
Should suffice. This isn't in the documentation but I _feel_ this is the way
to do it :-)
Groeten,
Patrick
--
Hieper Software
w: www.hieper.nl
e: email@hidden
_______________________________________________
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.