A quick question. I have the following code which gets the mod date of a file on a server:
- (void) sendRequestForLastModifiedHeaders
{
/* send a request for file modification date */
NSURLRequest *modReq = [NSURLRequest requestWithURL:[NSURL URLWithString:URLInput.text]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0f];
[[NSURLConnection alloc] initWithRequest:modReq delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
/* convert response into an NSHTTPURLResponse,
call the allHeaderFields property, then get the
Last-Modified key.
*/
NSHTTPURLResponse *foo = [(NSHTTPURLResponse *)response allHeaderFields];
NSString * last_modified = [NSString stringWithFormat:@"%@",
[[(NSHTTPURLResponse *)response allHeaderFields] objectForKey:@"Last-Modified"]];
NSLog(@"Last-Modified: %@", last_modified );
}
My main question is the following:
Does this call only send over the header? If the file is big I do not want the whole file being downloaded. That is why I'm checking the header.
+++++++++++++++++++++++++++++++++++++++ After the update this works... Thanks now looks like:
NSMutableURLRequest *modReq = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: URLInput.text]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0f];
[modReq setHTTPMethod:@"HEAD"];
get() The get() method of the Headers interface returns a byte string of all the values of a header within a Headers object with a given name. If the requested header doesn't exist in the Headers object, it returns null .
While you can't ready any headers of HTML response in JS, you can read Server-Timing header, and you can pass arbitrary key-value data through it.
As you have it now, you're probably downloading the whole file. The key is the http method used for the http request. By default, it's a GET request. What you want is a HEAD request. You don't want the file, you just want the server to return the response that you would get if you did, right?
To do that, you want to use a NSMutableURLRequest
and setHTTPMethod:
to construct a request with a method of HEAD, instead of GET.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With