Objective c 我可以要一台服务器吗';通过查询其HTTP头来设置服务器时间?
喂,我能得到Objective c 我可以要一台服务器吗';通过查询其HTTP头来设置服务器时间?,objective-c,http,networking,Objective C,Http,Networking,喂,我能得到http://www.google.com的服务器时间 如何在ObjC中执行此操作?当然: NSURLRequest *rq = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]; [NSURLConnection sendAsynchronousRequest:rq queue:[NSOperationQueue mainQueue] completionHandler:^(NS
http://www.google.com
的服务器时间
如何在ObjC中执行此操作?当然:
NSURLRequest *rq = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
[NSURLConnection sendAsynchronousRequest:rq queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *resp, NSData *data, NSError *err) {
NSDictionary *headers = [(NSHTTPURLResponse *)resp allHeaderFields];
NSString *dateString = [headers objectForKey:@"Date"];
NSLog(@"Google Server Date: %@", dateString);
}];
“日期”字段是否总是出现在标题中?@smilingpaper我不知道,我不是一个HTTP标准怪胎,但在谷歌(你感兴趣的)的特殊情况下,它就在那里。它是来自任何源服务器的必需标题,除了少数情况(1x响应和一些5XX)。@Kylar来了HTTP标准怪胎=P谢谢,它很有用,我还不知道呢。”微笑着问,我回答说:)