How Can I Send Http Post Request With Webview

I am building an app that uses a in-app login screen and a webview to show a certain mobile website.

The usename and password that are entered in the login screen should be passed on as parameters to a HTTP POST request to the website that will be displayed by the webview.

The webview has a “request” property. Can I also use this property to send POST requests?

I’d appreciate your responses!

I have worked around this issue by creating a local HTML file that contains javascript to create and submit a form.

If I open this file in the Webview it automatically submits the contents of a form to the external webpage using a HTTP POST.

Here’s the HTML:

\<HTML\>\<HEAD\> \<script\> function postwith (to,p) { var myForm = document.createElement("form"); myForm.method="post" ; myForm.action = to ; for (var k in p) { var myInput = document.createElement("input") ; myInput.setAttribute("name", k) ; myInput.setAttribute("id", k) ; myInput.setAttribute("value", p[k]); myForm.appendChild(myInput) ; } document.body.appendChild(myForm) ; myForm.submit() ; document.body.removeChild(myForm) ; }; function sendMyData() { var params = { username: "info@springmorning.nl", password: "MyPassword", appversion: "0.1.00a"} var action = "https://springmorningstuff.nl/"; postwith(action,params); }; \</script\> \</HEAD\> \<BODY onload="sendMyData()"\>forwarding\</BODY\> \</HTML\>

In the past, I have created a locally hosted page. Every request then comes to Corona and you can write a listener to filter for page submissions. If the submission needs to go to a server for user login, etc, recreate the request and return the result yourself to the webview control.

Thanks for responding.

I’m curious on how you would return the result to the webview control. I did not know it was possible to intercept the page submission and return your own HTTP response to the webview. Can you share an example?

Thanks!

~Rob.

I have worked around this issue by creating a local HTML file that contains javascript to create and submit a form.

If I open this file in the Webview it automatically submits the contents of a form to the external webpage using a HTTP POST.

Here’s the HTML:

\<HTML\>\<HEAD\> \<script\> function postwith (to,p) { var myForm = document.createElement("form"); myForm.method="post" ; myForm.action = to ; for (var k in p) { var myInput = document.createElement("input") ; myInput.setAttribute("name", k) ; myInput.setAttribute("id", k) ; myInput.setAttribute("value", p[k]); myForm.appendChild(myInput) ; } document.body.appendChild(myForm) ; myForm.submit() ; document.body.removeChild(myForm) ; }; function sendMyData() { var params = { username: "info@springmorning.nl", password: "MyPassword", appversion: "0.1.00a"} var action = "https://springmorningstuff.nl/"; postwith(action,params); }; \</script\> \</HEAD\> \<BODY onload="sendMyData()"\>forwarding\</BODY\> \</HTML\>

In the past, I have created a locally hosted page. Every request then comes to Corona and you can write a listener to filter for page submissions. If the submission needs to go to a server for user login, etc, recreate the request and return the result yourself to the webview control.

Thanks for responding.

I’m curious on how you would return the result to the webview control. I did not know it was possible to intercept the page submission and return your own HTTP response to the webview. Can you share an example?

Thanks!

~Rob.