load an URL into the WebView submitting POST data

Hi all,

I have to submit a post request when loading a webview. 

It’s possible on iOs and Android =>

iOS : http://belencruz.com/2013/03/load-a-post-request-into-an-uiwebview-in-ios/

Android : http://belencruz.com/2012/12/do-post-request-on-a-webview-in-android/

Is there a way to do that in Corona  ?

Looks like we only support GET with both native.newWebView and native.showWebPopUp (deprecated) with Corona SDK.  As an Enterprise User you probably could use those tutorials to implement a webView in native code and use POST.

Rob

it’s done. I can do that with a .js script in a local webview.

\<!DOCTYPE html\> \<html\> &nbsp; &nbsp; \<head\> &nbsp; &nbsp; &nbsp; &nbsp; \<meta charset="utf-8" /\> &nbsp; &nbsp; &nbsp; &nbsp; \<title\>Webview\</title\> &nbsp; &nbsp; \</head\> \<body\>&nbsp; \<script type= "text/javascript"\> var arg = window.location.search; var getdata = []; var datas = arg.substring(1); var separateDatas = datas.split("&"); for (var i = 0; i\< separateDatas.length;i++){ var data = separateDatas[i].split("="); getdata[data[0]] = data[1]; } var url = getdata["url"]; var name = getdata["\_name"]; var email = getdata["\_email"]; document.write('\<form name="f" action="'+url+'" method="POST" &nbsp;\>'); document.write('\<input type="hidden" &nbsp;value="' + name + '" &nbsp; &nbsp; name= "\_name" \>'); document.write('\<input type="hidden" &nbsp;value="' + email + '" &nbsp; name= "\_email" \>'); document.write('\</form\>'); document.forms["f"].submit(); \</script\> \</body\> \</html\>

Looks like we only support GET with both native.newWebView and native.showWebPopUp (deprecated) with Corona SDK.  As an Enterprise User you probably could use those tutorials to implement a webView in native code and use POST.

Rob

it’s done. I can do that with a .js script in a local webview.

\<!DOCTYPE html\> \<html\> &nbsp; &nbsp; \<head\> &nbsp; &nbsp; &nbsp; &nbsp; \<meta charset="utf-8" /\> &nbsp; &nbsp; &nbsp; &nbsp; \<title\>Webview\</title\> &nbsp; &nbsp; \</head\> \<body\>&nbsp; \<script type= "text/javascript"\> var arg = window.location.search; var getdata = []; var datas = arg.substring(1); var separateDatas = datas.split("&"); for (var i = 0; i\< separateDatas.length;i++){ var data = separateDatas[i].split("="); getdata[data[0]] = data[1]; } var url = getdata["url"]; var name = getdata["\_name"]; var email = getdata["\_email"]; document.write('\<form name="f" action="'+url+'" method="POST" &nbsp;\>'); document.write('\<input type="hidden" &nbsp;value="' + name + '" &nbsp; &nbsp; name= "\_name" \>'); document.write('\<input type="hidden" &nbsp;value="' + email + '" &nbsp; name= "\_email" \>'); document.write('\</form\>'); document.forms["f"].submit(); \</script\> \</body\> \</html\>

Hi Zed27,

Did you get this to work on Android devices? I am trying to parse the URL to get a variable using a method similar to your script but when I pass a variable in the webView request (e.g. webView:request( “graph.html?test=1”, system.ResourceDirectory ) the page won’t load on my Android device. It does work on iOS, however.

Thanks,

Jeff

Hei there,

I have the same problem.

The local html file with some javascript works fine on ios and the MAC simulator but not on Android :frowning:

Any idea what is the problem? And how to solve it?

Best,

Felix

Hi,

on Android your html file will only works in Documents directory, not Resource. 

z.

Hei Zed27 thanks!

That resolved the problem.

Whereas a plain html file works from within the resources folder…

(And to copy the html file to the documents folder on android you need to rename it to for example login.html.txt, just in case somebody wonders)

Best,

Felix

Hi Zed27,

Did you get this to work on Android devices? I am trying to parse the URL to get a variable using a method similar to your script but when I pass a variable in the webView request (e.g. webView:request( “graph.html?test=1”, system.ResourceDirectory ) the page won’t load on my Android device. It does work on iOS, however.

Thanks,

Jeff

Hei there,

I have the same problem.

The local html file with some javascript works fine on ios and the MAC simulator but not on Android :frowning:

Any idea what is the problem? And how to solve it?

Best,

Felix

Hi,

on Android your html file will only works in Documents directory, not Resource. 

z.

Hei Zed27 thanks!

That resolved the problem.

Whereas a plain html file works from within the resources folder…

(And to copy the html file to the documents folder on android you need to rename it to for example login.html.txt, just in case somebody wonders)

Best,

Felix