kCFStreamPropertyHTTPSProxyPort

kCFStreamPropertyHTTPSProxyPort

本文介绍了如何在SWIFT 3中向NSURLSession添加HTTPS代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用以下代码连接到代理服务器,并且仅适用于HTTP请求,但不适用于HTTPS。在iOS 9.0中,折旧了 kCFStreamPropertyHTTPSProxyHost kCFStreamPropertyHTTPSProxyPort

I have used the following code for connecting to the proxy server and works great for only HTTP requests but not for HTTPS. In iOS 9.0, kCFStreamPropertyHTTPSProxyHost and kCFStreamPropertyHTTPSProxyPort are depreciated.

let myPortInt = 12345;
let myProxyUrlString = "myProxyURL";

    let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration();
    sessionConfiguration.connectionProxyDictionary = [
        kCFNetworkProxiesHTTPEnable: true,
        kCFNetworkProxiesHTTPPort: myPortInt,
        kCFNetworkProxiesHTTPProxy: myProxyUrlString,
    ]
    let url = NSURL(string: endPointUrl)
    let postRequest = NSMutableURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 10.0)


    let jsonString =  bodyString
    postRequest.HTTPBody = jsonString
    postRequest.HTTPMethod = "POST"
    postRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")

    let session = NSURLSession(configuration: sessionConfiguration)
    let task = session.dataTaskWithRequest(postRequest){}


推荐答案

我找到了向NSURLsession添加HTTPS代理的解决方案

I found the solution for adding HTTPS proxy to NSURLsession

   let proxyDict : NSDictionary = ["HTTPEnable": Int(1), "HTTPProxy": myProxyUrlString, "HTTPPort": myPortInt, "HTTPSEnable": Int(1), "HTTPSProxy": myProxyUrlString, "HTTPSPort": myPortInt]

    let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration();

这篇关于如何在SWIFT 3中向NSURLSession添加HTTPS代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 23:08