I’m trying to make a POST request to a newly deployed vercel server. I am having trouble with the request in POSTMan and am getting error 500 when I try to request it from postman. My swift code only returns error 405. Here is my code:
func callRequest() {
let full_path: String = "https://suno-api-six-henna.vercel.app/api/generate"
let json: [String: Any] = ["prompt": "A popular heavy metal song about war, sung by a deep-voiced male singer, slowly and melodiously.",
"make_instrumental": "false", "wait_audio": "true"]
let jsonData = try? JSONSerialization.data(withJSONObject: json)
if let url = URL(string: full_path) {
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Accept")
request.httpBody = jsonData
do {
let task = URLSession.shared.dataTask(with: url) { data, response, error in
//This converts the optionals in to non optionals that could be used further on
//Be aware this will just return when something goes wrong
guard let data = data, let response = response, error == nil else{
print("Something went wrong: error: (error?.localizedDescription ?? "unkown error")")
return
}
print(response)
let test = String(decoding: data, as: UTF8.self)
print(test)
}
task.resume()
}
}
}
Feel free to use POSTMan or make a request to the link in the full_path
variable. Please help me debug! Could it be the headers?
9