connectionProxyDictionary 笔记

栏目: IOS · 发布时间: 6年前

内容简介:最近研究了下这个属性可以设置网络代理,默认值是 NULL,使用系统的代理设置。有一个比较巧妙的用法,可以通过设置为空字典可以禁止代理抓包(charles、fiddler等)。

最近研究了下 connectionProxyDictionary ,做一个简单的笔记。 官方文档 是这么描述的。

This property controls which proxy tasks within sessions based on this configuration use when connecting to remote hosts. The default value is NULL, which means that tasks use the default system settings.

这个属性可以设置网络代理,默认值是 NULL,使用系统的代理设置。

有一个比较巧妙的用法,可以通过设置为空字典可以禁止代理抓包(charles、fiddler等)。

上代码。

NSString* proxyHost =  @"192.168.12.23";//@"myProxyHost.com";
NSNumber* proxyPort = [NSNumber numberWithInt: 12345];


// 创建一个代理服务器,包括HTTP或HTTPS代理,当然还可以添加SOCKS,FTP,RTSP等
NSDictionary *proxyDict = @{
    (NSString *)kCFNetworkProxiesHTTPEnable  : [NSNumber numberWithInt:1],
    (NSString *)kCFNetworkProxiesHTTPProxy: proxyHost,
    (NSString *)kCFNetworkProxiesHTTPProxyPort: proxyPort,

    (NSString *)kCFNetworkProxiesHTTPSEnable : [NSNumber numberWithInt:1],
    (NSString *)kCFNetworkProxiesHTTPSProxy: proxyHost,
    (NSString *)kCFNetworkProxiesHTTPSProxyPort: proxyPort,
};

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
// 设置代理
configuration.connectionProxyDictionary = proxyDict;

// 禁止代理
configuration.connectionProxyDictionary = @{};

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

APIs

APIs

Daniel Jacobson、Greg Brail、Dan Woods / O'Reilly Media / 2011-12-24 / USD 24.99

Many of the highest traffic sites get more than half of their traffic not through the browser but through the APIs they have created. Salesforce.com (more than 50%) and Twitter (more than 75% fall int......一起来看看 《APIs》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器