How to programmatically add a proxy to an NSURLSession

前端 未结 6 1253
醉酒成梦
醉酒成梦 2020-12-01 05:02

Looking over the documentation of NSURLSession and NSURLSessionConfiguration, I was under the impression I should configure it with a dictionary li

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 05:28

    If anyone needs the swift version of this:

    Swift 3

    let sessionConfiguration = URLSessionConfiguration.default
    sessionConfiguration.connectionProxyDictionary = [
        kCFNetworkProxiesHTTPEnable as AnyHashable: true,
        kCFNetworkProxiesHTTPPort as AnyHashable: 999, //myPortInt
        kCFNetworkProxiesHTTPProxy as AnyHashable: "myProxyUrlString"
    ]
    let session = URLSession(configuration: sessionConfiguration)
    

提交回复
热议问题