1、
System.getProperties().remove("http.proxyHost");
System.getProperties().remove("http.proxyPort");
System.getProperties().remove("https.proxyHost");
System.getProperties().remove("https.proxyPort");
没错,这就是移除所有代理,但问题是如果移除全部,那其他的功能就必会受一些影响,没办法,只能
自己去看SDK,果然,Android是提供单个接口访问不带代理的,不废话,上代码
URL url = new URL(urlStr);
urlConnection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
嗯,很实在,然后又去看了一下OKhttp框架是否提供类似的操作,·······果然不愧是好框架:
OkHttpClient client = new OkHttpClient().newBuilder().proxy(Proxy.NO_PROXY).build();
2、
#pragma mark 禁止抓包方法
-(void)getProxyStatus {
NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings());
NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef _Nonnull)([NSURL URLWithString:@"https://www.baidu.com/"]), (__bridge CFDictionaryRef _Nonnull)(proxySettings)));
NSDictionary *settings = proxies[0];
if (![[settings objectForKey:(NSString *)kCFProxyTypeKey] isEqualToString:@"kCFProxyTypeNone"]){
//检测到抓包
}
}