gpt4 book ai didi

ios - 如何在 POST 请求中附加数据 - Swift

转载 作者:行者123 更新时间:2023-11-28 14:47:42 25 4
gpt4 key购买 nike

<分区>

如何快速将多个数据附加到 POST 请求。作为 postman 的附加屏幕截图,它在选择 x-www-form-urlencoded 选项时工作正常如何将 5 个数据附加到正文中,例如 'x-www-form-urlencoded' 选项。

这里是代码,

var request = URLRequest(url: urlString)
request.httpMethod = "POST"
request.setValue("application/x-www-form-urlencoded;charset=UTF-8", forHTTPHeaderField: "Content-Type")

var urlComponents = URLComponents()
urlComponents.queryItems = [
URLQueryItem(name: “***”, value: “***”),
URLQueryItem(name: "***", value: "***"),
URLQueryItem(name: "***", value: "***"),
URLQueryItem(name: "***", value: "***"),
URLQueryItem(name: "***", value: "***"),
]
request.httpBody = urlComponents.percentEncodedQuery?.data(using: String.Encoding.utf8)

let loadDataTask = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let _ = error{
completion(false,error)
}
else if let response = response as? HTTPURLResponse{
if response.statusCode != 200{
completion(false,error)
}
else{
do{
if let parsedData = try? JSONSerialization.jsonObject(with: data!, options: []){
let ff = parsedData as? Dictionary<String,Any>
print(ff)
}
}
}

}
}//let loadDataTask
loadDataTask.resume()
}

enter image description here

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com