Skip to content

Instantly share code, notes, and snippets.

@damirarh
Created June 2, 2013 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damirarh/5694415 to your computer and use it in GitHub Desktop.
Save damirarh/5694415 to your computer and use it in GitHub Desktop.
public static void PostAndNavigate(this WebView webView, string requestUri, IEnumerable<KeyValuePair<string, string>> formFields)
{
var formElements = String.Join("",
formFields.Select(p => String.Format(@"<input type=""hidden"" value=""{0}"" name=""{1}"">", p.Value, p.Key)));
var html = String.Format(
@"<html>
<head>
<script type=""text/javascript"">
function Submit()
{{
document.getElementById('pay').submit();
}}
</script>
</head>
<body>
<form id=""pay"" method=""POST"" action=""{0}"">
{1}
</form>
</body>
</html>", requestUri, formElements);
LoadCompletedEventHandler loadCompletedDelegate = null;
loadCompletedDelegate = (s, e) =>
{
webView.LoadCompleted -= loadCompletedDelegate;
webView.InvokeScript("Submit", null);
};
webView.NavigateToString(html);
webView.LoadCompleted += loadCompletedDelegate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment