14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AlamofireでCache-Controlを設定する

Last updated at Posted at 2015-04-19

REST APIを呼び出す際などにHTTPリクエストでCache-Controlを設定したい場合があると思います。

Alamofireでは、HTTPリクエストヘッダでCache-Controlを設定するのではなく、NSMutableURLRequestcachePolicyNSURLCacheを使って設定します。

例:キャッシュを使わずAPIを呼び出す場合

var request = NSMutableURLRequest(URL:NSURL(string:"http://example.com")!, cachePolicy:.ReloadIgnoringLocalCacheData, timeoutInterval:4.0)
request.addValue("OAuthのAccessToken", forHTTPHeaderField: "Authorization")

Alamofire
	.request(request)
	.response{(req, res, data, err) in
		// レスポンス処理
	}
14
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?