Skip to content

Instantly share code, notes, and snippets.

@lacyrhoades
Created August 24, 2018 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacyrhoades/4d1e2a4979838901fbe042653714250b to your computer and use it in GitHub Desktop.
Save lacyrhoades/4d1e2a4979838901fbe042653714250b to your computer and use it in GitHub Desktop.
struct TwilioEncoding: ParameterEncoding {
static var totallyNormal = TwilioEncoding()
// Twilio requires this weird encoding for arrays
func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
var request = try URLEncoding().encode(urlRequest, with: parameters)
if let data = request.httpBody, let string = String(data: data, encoding: .utf8) {
let replaced = string.replacingOccurrences(of: "%5B%5D=", with: "=")
request.httpBody = replaced.data(using: .utf8)
}
return request
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment