HTTP POST request body is empty
Hi,
First off, thanks for all the hard work. This module looks really promising!
Now over to the issue; for some reason it does not seem to work properly with HTTP POST requests. More specifically the POST-body seems to be missing from the request.
Basically what I've done is drop this module in place of the old WebView. The only change in my code is doing import WKWebView from 'react-native-wkwebview-reborn'; and replacing my old WebView with WKWebView.
Setting the following as source on the old WebView works;
source={
method: 'POST',
body: `samlResponse=${encodeURIComponent(saml)}`,
uri: authUrl
}
But it fails on this WKWebView module.
What I'm trying to do is POST an authentication SAML to a certain URL. Just setting a breakpoint in the code I can see that the properties are set on source:

But for some reason, the samlResponse is empty on the receiving endpoint. I've also checked with Charles Proxy that the POST-body is empty.
Seems like this might be a general problem with WKWebView though:
Just pinging back here to say that I found a workaround for my specific use-case.
You can inject html in the WebView source prop, which does a JavaScript POST for you.
Something like this should work;
render() {
let html = `<html><body>
<script type="text/javascript">
(function() {
function postSaml() {
var samlForm = document.createElement("form");
var samlInput = document.createElement("input");
samlForm.method = "POST";
samlForm.action = "${this.props.authUrl}";
samlInput.name = "samlResponse";
samlInput.value = "${this.props.saml}";
samlInput.type = "hidden";
samlForm.appendChild(samlInput);
document.body.appendChild(samlForm);
samlForm.submit();
}
if (window.loaded) { postSaml(); } else { window.onload = postSaml; }
})();
</script>
</body></html>`;
let source = { html, baseUrl: '' };
return (<WKWebView source={source} />)
}
This should also work with the Android/RN WebView.