HTTP Proxy support with WKWebView

2020-03-12 04:49发布

Is there a way to configure WKWebView to go through a HTTP Proxy server? I know this is possible with NSURLSession directly, but I want to configure it so that all requests through the WKWebView browser go through a proxy.

1条回答
混吃等死
2楼-- · 2020-03-12 05:30

NSURLSessionConfiguration has a direct interface(connectionProxyDictionary) to do that , so it can be done easily

But, WkWebView does not have any direct interface like that,it requests ,renders the content out-of-process and so you can imagine like WkWebview instance is sandboxed from the rest of your app

WkWeView even ignores the cookies(NSHTTPCookieStorage), caches(NSURLCache) and Credentials(NSCredentialStorage) of NSURLSession & NSURLConnection likewise these network classes can't access cookies,caches and credentials of WkWebView instance.

The UIWebView does not do it out-of-process and so you can use NSURLProtocol as demonstrated in CustomHTTPProtocol sample to proxy to a server.

As of iOS 10, still there is no support for NSURLProtocol in WkWebView so you can't proxy using WkWebView.

If your proxy server supports tunnelling(VPN) then you can use NetworkExtension.framework and its classes(NEVPNManager, NEVPNProtocol, NEVPNConnection etc..) to direct all the network traffic of your app through your proxy server.

查看更多
登录 后发表回答