有人知道如何在url请求中发送If Modified Since头吗?
我正在尝试获取一个状态码,以告诉我一个RSS页面是否已更新。
更新#1: 我能够进行以下测试:
NSURL *url = [NSURL URLWithString:self.url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:@"Tue, 18 Nov 2014 20:46:46 GMT" forHTTPHeaderField:@"If-Modified-Since"];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
int responseCode = (int)[httpResponse statusCode];
NSLog(@"All headers: %@", [httpResponse allHeaderFields]);
NSLog(@"Status code:: %d", responseCode);
}];
如果我删除整个iOS应用并运行它,我会得到304状态码,这很奇怪。但是,如果我注释掉添加"If-Modified-Since"值的那一行,并重新运行它,我就会得到200,但是当我取消注释并重新运行它时,304错误就不再出现,而是变成了200错误码。唯一可以让304错误再次出现的方法是将整个应用程序从我的iPhone设备上删除。
你有什么想法吗?
If-Modified-Since
头来执行此操作,但是我无法找到NSURLSession中的等效方法。有人知道如何在NSURLSession中实现此功能吗? - mkumar