ios - Swift 4/5 设置将代理添加到 WKWebview
问题描述
我一直在寻找一种方法来为 WKWebview 请求设置代理,但没有成功。
另一方面,我已经能够将代理设置为 http 请求
func createURLSessionConfiguration(_ host:String,_ port:String) -> URLSessionConfiguration {
let config = URLSessionConfiguration.default
config.requestCachePolicy = URLRequest.CachePolicy.reloadIgnoringLocalCacheData
config.connectionProxyDictionary = [AnyHashable: Any]()
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPEnable as String] = 1
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPSProxy as String] = host
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPSPort as String] = port
return config
}
但是我对你们的问题是如何将代理设置为 WKWebView?
我会非常感谢你的帮助
解决方案
WKWebView 无法进行 HTTP 代理 - NSURLProtocol 注册技巧在使用 WKWebView 时不起作用(它仅适用于 UIWebView)。
使用 WKURLSchemeHandler 可能也可以使用类似的技巧,但它不允许注册由 WKWebView 本地处理的方案,因此这实际上是不可能的。
推荐阅读
- reactjs - Tracker.autorun 在 react 的 componentDidMount 中不起作用
- javascript - 是否使用来自外部域的数据附加 iframe 而不是安全地进行 AJAX 调用?
- azure - HSM、应用服务器和数据库之间的交互是如何发生的?
- android - 改造中的错误 call.enqueue
- python - 使用python在html中搜索文本
- javascript - $.get 的 JavaScript 多重承诺问题
- java - 在 Dataflow 中执行聚合
- amazon-web-services - 工作区或 appstream 是否必须与 ec2 一起使用?
- ios - Gluon Mobile 应用程序在 iPhone Sumulator 上非常慢
- java - 使用 Java 8 流转换嵌套集合