Swift Alamofire为所有请求添加自定义标题 [英] Swift Alamofire add custom header to all requests
本文介绍了Swift Alamofire为所有请求添加自定义标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试添加自定义标题:
I tried to add custom header with this:
let manager = Manager.sharedInstance
manager.session.configuration.HTTPAdditionalHeaders = [
"Authorization": "Token \(token)"
]
但它不起作用,我做错了什么?
But it doesn't work, what am i doing wrong?
我需要在登录后添加此项,以便在所有请求中使用标题。
I need to add this after login, so that header will be used in all requests.
推荐答案
我不知道你在哪里做的,但是我的AlomoFire请求看起来像:
I don't know where you do that but my AlomoFire requests look like :
Alamofire.request(.GET, urlPath, parameters: parameters, headers: ["X-API-KEY": apiKey, "Content-type application":"json", "Accept application" : "json"]).responseJSON() { (req,res, data, error) in //blah blah }
我的猜测是,您可以将您的标题信息放入该标题数组中。
My guess is that you can put your header information into that headers array
这篇关于Swift Alamofire为所有请求添加自定义标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文