Hello,
I am trying to make a “POST” to my database but I have this error that is hindering my attempts to do so: Cannot convert value of type ‘()’ to expected argument type ‘Data’
it occurs around this block. Please help:
do {
let (data, _) = try await URLSession.shared.upload(for: request, from: encoded )
}
import UIKit
class ViewController: UIViewController {
var quote: Quote?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func updateButton(_ sender: Any) {
Task {
await replaceBrandName()
}
}
func replaceBrandName() async {
guard let encoded = try? JSONDecoder().allowsJSON5.encode(to: quote as! Encoder) else {
print("Faild to encode")
return
}
// create the url with URL
let url = URL(string: "https://www.goedash.com/_functions/quoteapi/quote")! // change server url accordingly
// now create the URLRequest object using the url object
var request = URLRequest(url: url)
request.httpMethod = "POST" //set http method as POST
// add headers for the request
request.addValue("application/json", forHTTPHeaderField: "Content-Type") // change as per server requirements
request.addValue("application/json", forHTTPHeaderField: "Accept")
do {
let (data, _) = try await URLSession.shared.upload(for: request, from: encoded )
}
}
}