Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 我可以要一台服务器吗';通过查询其HTTP头来设置服务器时间?_Objective C_Http_Networking - Fatal编程技术网

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谢谢,它很有用,我还不知道呢。”微笑着问,我回答说:)