うちのいぬ Tech Blog

Tech Blog of Uchinoinu/My dog

Sending HTTP Request with Custon header like "AccessToken" by Almofire, and Getting them by Rails 4.x

GET with Custom Header by Alamofire

let URL = NSURL(string: "https://dinner.please")!
let mutableURLRequest = NSMutableURLRequest(URL: URL)
let message = "I want to eat!"
mutableURLRequest.HTTPMethod = "GET"
mutableURLRequest.setValue(message, forHTTPHeaderField: "Meat")
let manager = Alamofire.Manager.sharedInstance

manager.request(mutableURLRequest)
  .response { request, response, data, error in
            }
.
.
.

Get them by Rails 4.x

request.headers["Meat"]
# => "I want to eat"