我为alamofire请求创建了一个通用类
我想以import tensorflow.keras.backend as K
的形式发送参数
如何将参数添加到我的aplication/x-www-form-urlencoded
我设法使用以下代码将参数urlRequest
添加到urlRequest中
application/json
我需要 do {
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: [])
} catch {
throw AFError.parameterEncodingFailed(reason: .jsonEncodingFailed(error: error))
}
这是我的参数
aplication/x-www-form-urlencoded
答案 0 :(得分:1)
下面是它对我迅速起作用的代码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()
答案 1 :(得分:0)
尝试:
guard let request_url = URL(string: Url) else { return }
let parameterDictionary = ["your parameter" : value]
var request = URLRequest(url: request_url)
request.httpMethod = "POST"
request.setValue("Application/json", forHTTPHeaderField: "Content-Type")
request.setValue("aplication/x-www-form-urlencoded", forHTTPHeaderField: "String")
guard let httpBody = try? JSONSerialization.data(withJSONObject: parameterDictionary, options: []) else {
return
}
request.httpBody = httpBody