Swift 阿拉莫菲尔JsonEncoding和URLCONCODING
我需要使用Alamofire发送补丁请求,我的问题是我需要在这个请求中同时使用URLEncoding和JSONEncodingSwift 阿拉莫菲尔JsonEncoding和URLCONCODING,swift,alamofire,kinto,Swift,Alamofire,Kinto,我需要使用Alamofire发送补丁请求,我的问题是我需要在这个请求中同时使用URLEncoding和JSONEncoding let url = URL(string: "https://kinto.dev.mozaws.net/v1/buckets/\(self.bucketName!)/collections/\(self.collectionName!)/records")! parameters?["data"] = kintoDictionary Alamofire.reques
let url = URL(string: "https://kinto.dev.mozaws.net/v1/buckets/\(self.bucketName!)/collections/\(self.collectionName!)/records")!
parameters?["data"] = kintoDictionary
Alamofire.request(url, method: .patch, parameters: self.parameters, encoding: JSONEncoding.default, headers: self.headers).responseJSON { (response) in
...
}
如何在此请求中添加带参数的URL编码??我应该使用NSURLRequest而不是URL吗?Swift 3.0
您的url需要删除空间,因此请使用下面的代码对您的url进行编码
你可以试试这个
let url = URL(string: "https://kinto.dev.mozaws.net/v1/buckets/\(self.bucketName!)/collections/\(self.collectionName!)/records")!
print(url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
parameters?["data"] = kintoDictionary
Alamofire.request(url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!, method: .patch, parameters: self.parameters, encoding: URLEncoding.default, headers: self.headers).responseJSON { (response) in
...
}
Swift 3.0
您的url需要删除空间,因此请使用下面的代码对您的url进行编码
你可以试试这个
let url = URL(string: "https://kinto.dev.mozaws.net/v1/buckets/\(self.bucketName!)/collections/\(self.collectionName!)/records")!
print(url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
parameters?["data"] = kintoDictionary
Alamofire.request(url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!, method: .patch, parameters: self.parameters, encoding: URLEncoding.default, headers: self.headers).responseJSON { (response) in
...
}