Re: Get the true time and date
Re: Get the true time and date
- Subject: Re: Get the true time and date
- From: Nicko van Someren <email@hidden>
- Date: Fri, 23 Apr 2004 18:59:06 +0100
On 23 Apr 2004, at 17:54, Lorenzo wrote:
I already know how to download files with NSURLConnection
but I cannot see the way to get the current and real date/time from my
server.
Most web servers (certainly Apache in the default configuration) give
the time of the access in the HTTP response headers. The delegate of
the NSURLConnection receives the message download:didReceiveResponse:
so you could access a web server with a suitable HTTP:// URL and try:
- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *hresp = (NSHTTPURLResponse *) response;
NSDictionary *theHeaders = [hresp allHeaderFields];
NSString *dateString = [theHeaders objectForKey: @"Date"];
// Do something with your date string here...
}
I typed the above in Mail.app so it's probably got bugs, but you get
the idea.
Note that if the user is behind some proxy server then they might well
get the date set on the proxy server instead. One way to deal with
this would be to fetch a page which is a CGI program returning the
server date. Another way to deal with it would be to ignore the
problem, since the number of users willing to mess with their proxy
server just to mess with your software registration process will be
small :-)
Nicko
_______________________________________________
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.