How it looks: curl https://token-vault.repeatphotos.xyz/token -H "Authorization: e11f18b4-5015-45ad-8276-18269a7bf047""
Response is string value. So the main question is, how to make a request and get value from this in swift?
I've tried something like this:
func changeApiKey() {
let url = URL(string: "https://token-vault.repeatphotos.xyz/token")
var request = URLRequest(url: url!)
request.httpMethod = "GET"
request.addValue("e11f18b4-5015-45ad-8276-18269a7bf047", forHTTPHeaderField: "Authorization")
let task = URLSession.shared.dataTask(with: url!) { data, response, error in
guard error == nil else {
print(error!)
return
}
guard let data = data else {
print("Data is empty")
return
}
let json = try! JSONSerialization.jsonObject(with: data, options: [])
print(json)
}
task.resume()
}
try something like this, works for me, it gives "newty-token"
func changeApiKey() {
if let url = URL(string: "https://token-vault.repeatphotos.xyz/token") {
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("text/plain",forHTTPHeaderField: "Accept")
request.setValue("e11f18b4-5015-45ad-8276-18269a7bf047", forHTTPHeaderField: "Authorization")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard error == nil else {
print(error!)
return
}
guard let data = data else {
print("Data is empty")
return
}
let result = String(data: data, encoding: .utf8)
print("result: \(result)")
}
task.resume()
}
}