iOS 使用socks5代理服务器
2018-09-04 本文已影响115人
redexpress
iOS 使用socks5代理服务器需要配置URLSessionConfiguration,如下:
let dict: [String:Any] = [kCFStreamPropertySOCKSProxyPort as String: 9180, kCFStreamPropertySOCKSProxyHost as String: "127.0.0.1"]
let configuration = URLSessionConfiguration.ephemeral
configuration.connectionProxyDictionary = dict
let session = URLSession(configuration: configuration)
let task = session.dataTask(with: URL(string: "http://httpbin.org/get")!){
data, response, error in print(response ?? "")
}
task.resume()