• 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
Re: NSURL and response header
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURL and response header


  • Subject: Re: NSURL and response header
  • From: Becky Willrich <email@hidden>
  • Date: Fri, 14 Feb 2003 15:05:44 -0800

Using NSURL - now have a need to get at the response header for the
Content-length. NSURL does not seem to provide any support for doing this.

If you ask for [NSURL propertyForKey:@"Content-Length"], you will get the value of the Content-Length header as a string. Unfortunately, -propertyForKey: will start a fresh download (really a HEAD request) for that value; if you use NSURLHandle directly instead, you can get both the data and the content-length at once. Assuming you want asynchronous behavior (synchronous is somewhat easier), you want something like:

NSURLHandle *handle = [myURL URLHandleUsingCache:cachedHandleIsOK];
[handle addClient:myClient];
[handle loadInBackground];

Then when myClient receives the first URLHandle:resourceDataDidBecomeAvailable: message, you can get the value of the Content-Length header by doing:

NSString *lengthAsString = [handle propertyForKey:@"Content-Length"];
int length = [lengthAsString intValue];

This is true for any HTTP header - unless NSURLHandle recognizes a string as one of the special property keys defined in NSURLHandle.h, it will attempt to look up the string as an HTTP header.

Hope that helps,
REW
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

References: 
 >NSURL and response header (From: "Arthur Lewis" <email@hidden>)

  • Prev by Date: NSURL and response header
  • Next by Date: Altering CFSocket Callback Behavior
  • Previous by thread: NSURL and response header
  • Next by thread: Altering CFSocket Callback Behavior
  • Index(es):
    • Date
    • Thread