问题
Any idea how to handle eTags at client side? We are planning to use eTags with images in our application which are coming from the server.
For what is eTag please see this: http://en.wikipedia.org/wiki/HTTP_ETag
回答1:
Starting points for your study ...
NSMutableURLRequest
Here you can set eTag value for you request.
[self addValue:eTag forHTTPHeaderField:@"If-None-Match"];
This request is usable with NSURLConnection.
NSURLConnectionDelegate
Delegate of your NSURLConnection has method ...
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
... where response in your case is NSHTTPURLResponse
.
You should check response statusCode in another delegate's method ...
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
... status code 304 is received when remote object is not modified. If remote object is modified and eTag is supported, you can find it in [response allHeaderFields]
.
来源:https://stackoverflow.com/questions/5026278/handling-etags-on-iphone