• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
HEAD request using NSURLConnection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: HEAD request using NSURLConnection
      • From: Daryn <email@hidden>
  • Prev by Date: Re: newbie question....reading from flat file
  • Next by Date: Re: calling external java from cocoa
  • Previous by thread: Re: GLUT and nib files, creates more than one app on 10.2
  • Next by thread: Re: HEAD request using NSURLConnection
  • Index(es):
    • Date
    • Thread