想象一下,我在Flash应用程序中有一个带有两个字段input1和input2的表单。当用户完成填写此表单时,它将转到php页面。
目前,我正在使用$_GET
方法发送数据
像这样:
var request:URLRequest;
request = new URLRequest("http://site.com/page.php?data1="+input1.text+"&data2="+input2.text);
navigateToURL(request);
在PHP代码中:
$_GET["data1"];
$_GET["data2"];
但是这样,信息保留在URL中。如何通过$_POST
发送此内容?
答案 0 :(得分:5)
简而言之:
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
使用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
*/