Skip to content

Instantly share code, notes, and snippets.

@yellowred
Created September 28, 2016 04:48
Show Gist options
  • Save yellowred/7757104e00c01076b5a85548c7bdcebf to your computer and use it in GitHub Desktop.
Save yellowred/7757104e00c01076b5a85548c7bdcebf to your computer and use it in GitHub Desktop.
Alamofire custom parameter encoder
extension String: ParameterEncoding {
public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
var request = try urlRequest.asURLRequest()
request.httpBody = data(using: .utf8, allowLossyConversion: false)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
return request
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment