httpBody

自定义格式
func postHttp(params: [String:Any]) -> Void {
request.httpBody = try! JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
}


//使用
let params = ["id":dataApiDrugs.descriptionID] as [String:Any]
self.postHttp(url: "https://siboxapi.herokuapp.com/description/select", params: params)
使用模型
func postHttp(params: PostParm) -> Void {
request.httpBody = try! JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
do {
request.httpBody = try JSONEncoder().encode(parm)
} catch { return }
}

//api接口参数结构
struct PostParm: Codable {
let id: Int16
}

//使用
let myParam = PostParm(id: dataApiDrugs.descriptionID)
self.postHttp(url: "https://siboxapi.herokuapp.com/description/select", params: myParam)