“Permintaan HTTP Swift” Kode Jawaban

Permintaan HTTP Swift

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()
Vel

Permintaan HTTP Swift

 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()
Vel

Jawaban yang mirip dengan “Permintaan HTTP Swift”

Pertanyaan yang mirip dengan “Permintaan HTTP Swift”

Lebih banyak jawaban terkait untuk “Permintaan HTTP Swift” di Swift

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya