towry
6/21/2017 - 1:52 AM

swift: request a web page.

swift: request a web page.

//: Playground - noun: a place where people can play

import Foundation
import PlaygroundSupport

URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)

let url = URL(string: "http://www.baidu.com")

let task = URLSession.shared.dataTask(with: url!) {data, response, error in
    guard let data = data, error == nil else { return }
    print(NSString(data: data, encoding: String.Encoding.utf8.rawValue))
}

#if ABC
    print("hahahahah")
#endif

print("begin")

task.resume()

PlaygroundPage.current.needsIndefiniteExecution = true