Gon*_*nzo 3 php flash actionscript-3
想象一下,我在Flash应用程序中有一个表单,有两个字段input1和input2.当用户完成填写此表单时,它将转到php页面.目前,我正在使用该$_GET
方法发送数据.
像这样:
var request:URLRequest;
request = new URLRequest("http://site.com/page.php?data1="+input1.text+"&data2="+input2.text);
navigateToURL(request);
Run Code Online (Sandbox Code Playgroud)
并在PHP代码中:
$_GET["data1"];
$_GET["data2"];
Run Code Online (Sandbox Code Playgroud)
但这样,信息就会保留在URL中.我该怎么发送这个$_POST
?
在AS 3中,用于指定您的请求的URLRequest类有一个方法属性,可用于为提交方法设置HTTP选项,您需要使用URLRequestMethod常量POST将其设置为POST以获得完美的表单,或者您可以使用"POST"字符串.
所以简而言之:
var url:String = "http://localhost/myPostReceiver.php";
var request:URLRequest = new URLRequest(url);
var requestVars:URLVariables = new URLVariables();
requestVars.foo = "bar";
// ... fill in your data
request.data = requestVars;
request.method = URLRequestMethod.POST;
// after this load your url with an UrlLoader or navigateToUrl
Run Code Online (Sandbox Code Playgroud)
使用Adobe Air时您需要使用URLLoader类而不是navigateToURL(),原因如下:
参数request:URLRequest - 一个URLRequest对象,指定要导航到的URL.
对于在Adobe AIR中运行的内容,当使用navigateToURL()函数时,运行时会将使用POST方法的URLRequest(其方法属性设置为URLRequestMethod.POST)视为使用GET方法.
基本上每当你想正确使用POST set方法时,如navigateToUrl的文档所示:
接下来在php中你将收到超全局$ _POST数组中的变量,你可以在其中访问它:
<?php
$foo = $_POST['foo'];
/* $foo now contains 'bar'
assignment to another value is not necessary to use $_POST['foo']
in any function or statement
*/
Run Code Online (Sandbox Code Playgroud)