简体   繁体   English

navigateToURL通过POST发送数据到php页面

[英]navigateToURL sending data via POST to php page

Imagine that I have a form in a flash application with two fields, input1 and input2. 想象一下,我在Flash应用程序中有一个表单,其中包含两个字段input1和input2。 And when the user finish filling this form, it goes to a php page. 当用户完成填写此表单时,它将转到php页面。 At the moment, I'm using the $_GET method to send the data. 目前,我正在使用$_GET方法发送数据。
Like this: 像这样:

var request:URLRequest;
request = new URLRequest("http://site.com/page.php?data1="+input1.text+"&data2="+input2.text);
navigateToURL(request);

And in the php code: 并在PHP代码中:

$_GET["data1"];
$_GET["data2"];

But this way, the information stays in the URL. 但这样,信息就会保留在URL中。 How can I send this via $_POST ? 我怎么能通过$_POST发送这个?

in AS 3 the URLRequest class you use to specify your request has a method property which can be used to set he HTTP option for submission method, you'll need to set it to POST using URLRequestMethod constant POST for perfect form or you could use a "POST" string. 在AS 3中,用于指定您的请求的URLRequest类有一个方法属性,可用于为提交方法设置HTTP选项,您需要使用URLRequestMethod常量POST将其设置为POST以获得完美的表单,或者您可以使用“POST”字符串。

You can find a comprehensive example on snipplr 你可以在snipplr上找到一个全面的例子

so in a nutshell: 所以简而言之:

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

When using Adobe Air You'd need to use the URLLoader class instead of navigateToURL() because of the following tidbit: 使用Adobe Air时您需要使用URLLoader类而不是navigateToURL(),原因如下:

Parameters request:URLRequest — A URLRequest object that specifies the URL to navigate to. 参数request:URLRequest - 一个URLRequest对象,指定要导航到的URL。

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 . 对于在Adobe AIR中运行的内容,当使用navigateToURL()函数时,运行时会将使用POST方法的URLRequest(其方法属性设置为URLRequestMethod.POST)视为使用GET方法

Basically whenever you want to use POST set method correctly, as also indicated by the documentation for navigateToUrl : 基本上每当你想正确使用POST set方法时,如navigateToUrl的文档所示:

next in php you'd be receiving the variable in the superglobal $_POST array, where you could access it as such: 接下来在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
*/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM