24 lines
604 B
Swift
24 lines
604 B
Swift
//
|
|
// URLRequest+Body.swift
|
|
// Fervor
|
|
//
|
|
// Created by Shadowfacts on 11/25/21.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension URLRequest {
|
|
mutating func setURLEncodedBody(params: [String: String?]) {
|
|
setValue("application/x-www-form-urlencoded; charset=utf8", forHTTPHeaderField: "Content-Type")
|
|
var data = Data()
|
|
for (k, v) in params where v != nil {
|
|
data.append(contentsOf: k.utf8)
|
|
data.append(61)
|
|
data.append(contentsOf: v!.utf8)
|
|
data.append(38)
|
|
}
|
|
let _ = data.dropLast() // drop last &
|
|
httpBody = data
|
|
}
|
|
}
|