I upgraded my project to Swift 3 and Alamofire 4. I used custom encoding, but changed it to other encoding methods. I cannot find an alternative / equivalent to this:
alamoFire.request(urlString, method: HTTPMethod.post, parameters: [:], encoding: .Custom({ (convertible, params) in let mutableRequest = convertible.URLRequest.copy() as! NSMutableURLRequest let data = (body as NSString).data(using: String.Encoding.utf8) mutableRequest.httpBody = data return (mutableRequest, nil) }), headers: headers()).responseJSON { (responseObject) -> Void in switch responseObject.result { case .success(let JSON): success(responseObject: JSON) case .failure(let error): failure(error: responseObject) } }
I also tried to make the URLRequest object and a simple request of it also giving me errors
var request = URLRequest(url: URL(string: urlString)!) let data = (body as NSString).data(using: String.Encoding.utf8.rawValue) request.httpBody = data request.httpMethod = "POST" request.allHTTPHeaderFields = headers() alamoFire.request(request).responseJSON { (responseObject) -> Void in switch responseObject.result { case .success(let JSON): success(JSON) case .failure(let error): failure(responseObject, error) } }
Call me in a specific direction how to connect httpbody using Alamofire 4
ios swift3 alamofire
Raheel Sadiq Sep 19 '16 at 12:43 2016-09-19 12:43
source share