Handling eTags on iPhone

≯℡__Kan透↙ 提交于 2019-12-22 06:49:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!