How do I make an HTTP request in Swift?

前端 未结 20 1404
不知归路
不知归路 2020-11-22 05:10

I read The Programming Language Swift by Apple in iBooks, but cannot figure out how to make an HTTP request (something like cURL) in Swift. Do I need to import Obj-C classes

20条回答
  •  甜味超标
    2020-11-22 05:55

    KISS answer:

    URLSession.shared.dataTask(with: URL(string: "https://google.com")!) {(data, response, error) in
        print(String(data: data!, encoding: .utf8))
    }.resume()
    

提交回复
热议问题