Alamofire 2.0 and Swift 2 - Header is not working. See how to fix it

后端 未结 1 474
广开言路
广开言路 2021-01-17 02:37

When I upgraded my project to swift 2 with Alamofire 2 headers stopped working without any errors in code. The reason is that he

相关标签:
1条回答
  • 2021-01-17 03:29

    You can fix the header problem by sending headers in requests.

    // login with Alamofire 2.0 and Swift 2.0 - WITH HEADER
    func loginAlamofire_2(username:String) {
        manager.request(.POST, "login_url", parameters: ["username" : username], encoding: ParameterEncoding.JSON, headers: ["Authorization": "yourToken"])
            .response{ (request, response, data, error) -> Void in
                if error != nil{
                    print("error!")
                } else {
                    print("welcome")
                }
        }
    }
    
    0 讨论(0)
提交回复
热议问题