let url = URL(string: "http://www.example.com")!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
task.resume()
let url = URL(string: <#T##URL String#>)
guard let requestUrl = url else { fatalError() }
var request = URLRequest(url: requestUrl)
request.httpMethod = "POST"
// Set Request Header
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
// Set HTTP Body
let newTodoItem = RequestModel(id: 300, task: "")
let jsonData = try JSONEncoder().encode(newTodoItem)
request.httpBody = jsonData
// Make Request
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let error = error {
print("Error took place (error)")
return
}
guard let data = data else {return}
}
task.resume()
let url = URL(string: "http://www.example.com")!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
task.resume()
let url = URL(string: <#T##URL String#>)
guard let requestUrl = url else { fatalError() }
var request = URLRequest(url: requestUrl)
request.httpMethod = "POST"
// Set Request Header
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
// Set HTTP Body
let newTodoItem = RequestModel(id: 300, task: "")
let jsonData = try JSONEncoder().encode(newTodoItem)
request.httpBody = jsonData
// Make Request
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let error = error {
print("Error took place (error)")
return
}
guard let data = data else {return}
}
task.resume()