How Intercept all the Http Request/Responce(GET,POST) in a website which loads on WkWebView from swift.

I need to Intercept all HTTP requests/responses (GET/POST) in a website that loads on WkWebView in the Swift app. I tried to work with this plugin [https://github.com/tommy19970714/WebKitURLProtocol]. I was able to intercept with GET request, But it cannot work with POST requests because the POST request body is always missing when I intercept it on the swift.

Answered by Ptit-Xav in 730648022

You can do this in the navigation delegate method decidePolicy :

optional func webView(
_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void

)

the navigationAction parameter contains the URLRequest which contains the httpBody of the POST request.

Accepted Answer

You can do this in the navigation delegate method decidePolicy :

optional func webView(
_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void

)

the navigationAction parameter contains the URLRequest which contains the httpBody of the POST request.

How Intercept all the Http Request/Responce(GET,POST) in a website which loads on WkWebView from swift.
 
 
Q