请找到附带的代码
let headers = ["Authorization": token,"Content-Type": "application/Json"] Alamofire.request("http://localhost:8000/create",method: .post,parameters: parameters,enCoding: JsONEnCoding.default,headers: headers).responseJsON { response in}解决方法 以这种方式添加标题
let headers = ["Authorization" : "Bearer "+accesstoken!+"","Content-Type": "application/Json"]Alamofire.request(URL,headers: headers).responseJsON { (response:DataResponse) in switch(response.result) { case .success(let value):
//为Json序列化添加成功:
let JsON = try JsONSerialization.JsonObject(with: response.data! as Data,options:JsONSerialization.ReadingOptions(rawValue: 0)) guard let JsONDictionary: NSDictionary = JsON as? NSDictionary else { return } completionHandler(JsONDictionary as? NSDictionary,nil) case .failure(let error): completionHandler(nil,error as NSError?) break } }总结
以上是内存溢出为你收集整理的swift – 带标头的Alamofire POST请求全部内容,希望文章能够帮你解决swift – 带标头的Alamofire POST请求所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)