Alamofire中的“kCFErrorDomainCFNetwork Code = 310”错误

时间:2017-09-02 23:28:00

标签: ios alamofire

我想使用代理服务器进行http Session我尝试免费代理它工作正常但是当我使用代理服务器验证它不起作用!这是我的代码:

  var proxyConfiguration = [NSObject: AnyObject]()
    proxyConfiguration[kCFNetworkProxiesHTTPProxy] = "proxy" as AnyObject?
    proxyConfiguration[kCFNetworkProxiesHTTPPort] = 29842 as AnyObject?
    proxyConfiguration[kCFNetworkProxiesHTTPEnable] = 1 as AnyObject?
   proxyConfiguration[kCFStreamPropertyHTTPSProxyHost ] = "proxy" as AnyObject
proxyConfiguration[kCFStreamPropertyHTTPSProxyPort] = 9292 as AnyObject
   proxyConfiguration[kCFProxyUsernameKey] = "Myusername"  as AnyObject
   proxyConfiguration[kCFProxyPasswordKey] = "Mypassord" as AnyObject
    let cfg = Alamofire.SessionManager.default.session.configuration
    cfg.connectionProxyDictionary = proxyConfiguration

    let ip = URL(string: "https://api.ipify.org?format=json")

    requestManager = Alamofire.SessionManager(configuration: cfg)
    requestManager.request(ip!).response { response in
        print("Request: \(response.request)")
        print("Response: \(response.response)")
        print("Error: \(response.error)")

        if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
            print("Data: \(utf8Text)")
        }
    }

0 个答案:

没有答案