LoginSignup
7
7

More than 5 years have passed since last update.

AlamofireでUser-Agentを変更する

Last updated at Posted at 2015-09-24

アプリでAPIなどにリクエストをする場合に、UAを書き換える必要があったためAlamofireを使用した場合の実装です。

コード

// managerのインスタンスを取得してUAを書き換え
let manager = Alamofire.Manager.sharedInstance
manager.session.configuration.HTTPAdditionalHeaders = [
    "User-Agent": "Hogehoge"
]

// リクエストの方法は特に変更なし
manager.request(.GET, "https://api.com/user/get").responseJSON(
            options: NSJSONReadingOptions(), 
            completionHandler: { (request, response, JSON, error) -> Void in
                println(JSON)
            })

参考

7
7
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
7
7