我为alamofire请求创建了一个通用类
我想将参数发送为aplication/x-www-form-urlencoded
如何将参数添加到我的urlRequest
我设法使用以下代码将参数作为application/json
添加到urlRequest
do {
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: [])
} catch {
throw AFError.parameterEncodingFailed(reason: .jsonEncodingFailed(error: error))
}
我需要
aplication/x-www-form-urlencoded
类似的东西这是我的参数
case .ewalletData :
return [K.APIParameterKey.token :"OP8JHOEOZ5KJW1X",K.APIParameterKey.fromMobile:"true",K.APIParameterKey.adminName:"binaryecom",K.APIParameterKey.limit:"100",K.APIParameterKey.offset:"0",K.APIParameterKey.userName:"OC6DGH"]
最佳答案
这是它迅速为我工作的代码4:
let postString = "your parameter="+value+"&your parameter="+value request.httpBody = postString.data(using: .utf8) let task = URLSession.shared.dataTask(with: request, completionHandler: completionHandle) task.resume()