I'm developing a Windows phone 8.1 app and there's this scenario where I should open the webview for the user to enter the card details. Once the card details are entered and processed, the payment API will send the transaction details back as a POST request to the webview. I'm not able to get the POST data, tried so many methods.
How do I get the post data returned back from the server? Thanks in Advance
If you have access to webpage code then you can use WebBrowser.ScriptNotify for transfering data from webpage to WP
Found a way to do this, actually the Server POST request had all the arguments in the Querystring itself
Handled the Navigation_Completed event of the webview, the args URI will have all the details required
Answer for UWP.
Important Note: I have html document locally in localcache folder. I open it in webview using ms-appdata://
scheme.
Story of infinite troubles (may be it some you some time):
If I sent the POST request, I got nothing. I get WebView_NavigationStarting
event, but the Uri only was transferred. No POST data.
I try to debug using alert
. Just to realize that alert
doesn't work in WebView
.
I found the fix that makes alert
works using ScriptNotify
events. Just to realize that ScriptNotify
doesn't work with ms-appdata://
scheme. So the fix didn't work as well.
I learned how debug in VS by going to Project settings / Debug / Debugger type / Application process and select "Script". Then I realized that I can't put breakpoints in script in Visual Studio. And then I found a little hack -- put the word "debugger;" in your javascript code and VS will stop there. And you can debug using F10/F11. Oh, yeah, baby!
Then I finally gave up and changed it to GET request. Just to realize that it only works until form data exceed ~2K. After that nothing. NavigationStarting
never fired, just nothing happens.
Finally, here the solution:
private async void WebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
string result = await this.WebView.InvokeScriptAsync("eval", new string[] { "$('form').serialize()" });
}
Not really elegant, but it works!!! And I was able to transfer 20K+ this way. This is exactly what I needed.