Re: NSURL and response header
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.