HEAD request using NSURLConnection
HEAD request using NSURLConnection
- Subject: HEAD request using NSURLConnection
- From: Daniel Miao <email@hidden>
- Date: Thu, 22 Jan 2004 19:29:34 -0500
Hi,
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];
long long dataLength = [response expectedContentLength];
Eventually, the call to [NSURLConnection sendSynchronousRequest:]
returns, but the problem is that there is a long delay. The first URL
I tried was a file on my local machine served up by apache. The delay
for that request was about 18 seconds. The second URL pointed to
google (
http://www.google.com/logos/lunarnewyear04.gif). That took
about 4 minutes.
Watching the packets, it seems that the HTTP request and response get
sent and returned right away, but the client does not close the
connection after receiving the header. Maybe NSURLConnection is
expecting to receive actual body data before closing or something. I'm
not sure. In the end, the call to [NSURLConnection
sendSynchronousRequest: ] eventually returns when the _server_ closes
the connection (by sending a FIN packet). This happens in asynchronous
mode of NSURLConnection as well, when using a delegate.
So has anyone encountered this issue before? Any help would be
appreciated.
Thanks!
Daniel
_______________________________________________
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.