在iOS中,如何读取源自WKWebView的NSURLRequest中的多部分表单数据? [英] In iOS, how to read the multi part form data in the NSURLRequest originating from a WKWebView?
问题描述
在WKWebView中,我们有一个多部分的POST请求,我们需要检查它并有条件地对其进行处理.
In our WKWebView, we have a multi part form POST request which we need to inspect and conditionally handle.
当前,我们正在尝试使用WKNavigationDelegate的webView:decidePolicyForNavigationAction:decisionHandler:
方法来获得对NSURLRequest的访问权限. (navigationAction.request
).
Currently, we're trying this using the WKNavigationDelegate's webView:decidePolicyForNavigationAction:decisionHandler:
method to gain access to the NSURLRequest. (navigationAction.request
).
但是,当我们在此处检查请求时,我们可以验证它是POST的多部分形式,但是,[request HTTPBody]
返回nil
.
But when we inspect the request here, we can verify that it is the multi part form POST, however, the [request HTTPBody]
returns nil
.
推荐答案
不幸的是,这是WebKit中的错误:((::
Unfortunately it is the bug in WebKit :(( :
- https://bugs.webkit.org/show_bug.cgi?id=140188
- https://bugs.webkit.org/show_bug.cgi?id=145410
在某些情况下,可以使用Florent Crivello提到的解决方法( https://bugs.webkit.org/show_bug.cgi?id=145410#c14 ):
For some cases mentioned workaround from Florent Crivello can be used (https://bugs.webkit.org/show_bug.cgi?id=145410#c14):
NSString *javascriptPOSTRedirect = @"\
var form = document.createElement('form');\
form.method = 'POST';\
form.action = '<URL>';\
\
var input = document.createElement('input');\
input.type = 'text';\
input.name = '<key>';\
input.value = '<value>';\
form.appendChild(input);\
form.submit();";
[webView evaluateJavaScript:javascriptPOSTRedirect completionHandler:^(id _Nullable content, NSError * _Nullable error) {
// Your thing
}];
这篇关于在iOS中,如何读取源自WKWebView的NSURLRequest中的多部分表单数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!