Https代理到URLSession

时间:2017-10-24 19:48:45

标签: swift nsurlsession macos-high-sierra

我的代码:

init() {
        let configuration = URLSessionConfiguration.default
        configuration.httpCookieStorage = HTTPCookieStorage.shared
        configuration.requestCachePolicy = .reloadIgnoringLocalCacheData
        configuration.urlCache = nil
        var proxy = [AnyHashable: Any]()
        proxy[AnyHashable(kCFNetworkProxiesHTTPSEnable)] = 1
        proxy[AnyHashable(kCFNetworkProxiesHTTPSProxy)] = "..."
        proxy[AnyHashable(kCFNetworkProxiesHTTPSPort)] = 14283
        proxy[AnyHashable(kCFProxyUsernameKey)] = "..."
        proxy[AnyHashable(kCFProxyPasswordKey)] = "..."
        configuration.connectionProxyDictionary = proxy

当我运行应用程序时,我看到了:

2017-10-25 00:45:44.768947+0500 ... Api[58675:12224660] *** WARNING: CFMachPortSetInvalidationCallBack() called on a CFMachPort with a Mach port (0x3613) which does not have any send rights.  This is not going to work.  Callback function: 0x7fff389e734f
2017-10-25 00:45:44.769328+0500 ... Api[58675:12224660] TIC Read Status [1:0x100f91800]: 1:57
2017-10-25 00:45:44.798125+0500 ... Api[58675:12224660] Task <4EFD78A7-1055-4D1C-9322-D0954B2B3760>.<1> HTTP load failed (error code: 310 [4:-2096])
2017-10-25 00:45:44.798300+0500 ... Api[58675:12224656] Task <4EFD78A7-1055-4D1C-9322-D0954B2B3760>.<1> finished with error - code: 310
URL Session Task Failed:  The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 310.)
Program ended with exit code: 0

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

用户名和密码不正确,或提及的端口被任何其他程序使用。重新启动手机并运行此应用,然后再次检查。