想象一下,我在Flash应用程序中有一个表单,其中包含两个字段input1和input2.当用户完成填写此表单时,它将转到PHP页面.
目前,我正在使用$_GET方法发送数据.
像这样:
var request:URLRequest;
request = new URLRequest("http://site.com/page.PHP?data1="+input1.text+"&data2="+input2.text);
navigatetoURL(request);
$_GET["data1"];
$_GET["data2"];
但这样,信息就会保留在URL中.我怎么能通过$_POST发送这个?
解决方法:
在AS 3中,用于指定您的请求的URLRequest类具有method属性,可用于设置提交方法的HTTP选项,您需要使用URLRequestMethod常量POST将其设置为POST以获得完美的表单,或者您可以使用“POST”字符串.
你可以在snipplr找到comprehensive example
所以简而言之:
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(),原因如下:
Parameters
request:URLRequest — A URLRequest object that specifies the URL to navigate to.For content running in Adobe AIR, when using the navigatetoURL() function, the runtime treats a URLRequest that uses the POST method (one that has its method property set to URLRequestMethod.POST) as using the GET method.
基本上每当你想正确使用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
*/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。