In our WKWebView, we have a multi part form POST request which we need to inspect and conditionally handle.
Currently, we're trying this using the WKNavigationDelegate's webView:decidePolicyForNavigationAction:decisionHandler:
method to gain access to the NSURLRequest. (navigationAction.request
).
But when we inspect the request here, we can verify that it is the multi part form POST, however, the [request HTTPBody]
returns nil
.
The request might contain a body stream. If so, and if you can modify the URL request, you could potentially read from that stream, then replace the request with a new one that uses a body data object.
Failing that, I think the only way to handle it would be to register a custom protocol handler that checks to see if it needs to handle it, and if so, handles it, and if not, either refuses it (if you can detect it without reading from the stream) or reissues it with some sort of tag that you can recognize (to avoid your protocol handler touching it the next time).
Unfortunately it is the bug in WebKit :(( :
For some cases mentioned workaround from Florent Crivello can be used (https://bugs.webkit.org/show_bug.cgi?id=145410#c14):
Althrough i didn't found a docu for this, my shot would be that for security reasons the body in the request is empty, or assigned later than in
webView:decidePolicyForNavigationAction:decisionHandler: