Handling eTags on iPhone

Any idea how to handle eTags on the client side? We plan to use eTags with images in our application that come from the server.

What is eTag, see this: http://en.wikipedia.org/wiki/HTTP_ETag

+4
source share
1 answer

Starting points for your research ...

NSMutableURLRequest

Here you can set the eTag value for your request.

[self addValue:eTag forHTTPHeaderField:@"If-None-Match"]; 

This query can be used with NSURLConnection.

NSURLConnectionDelegate

The delegate of your NSURLConnection has a method ...

 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 

... where is the answer in your case NSHTTPURLResponse .

You should check the statusCode status in another delegate method ...

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection 

... status code 304 is received when the remote entity does not change. If the remote object is modified and supported by eTag, it can be found in [response allHeaderFields] .

+6
source

Source: https://habr.com/ru/post/1340136/


All Articles