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

标签 php actionscript-3 flash

假设我在 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 发送?

最佳答案

在 AS 3 中 URLRequest您用来指定请求的类有一个 method可用于设置提交方法的 HTTP 选项的属性,您需要使用 URLRequestMethod 将其设置为 POST常量 POST以获得完美的形式,或者您可以使用“POST”字符串。

你可以找到一个comprehensive examplesnipplr

简而言之:

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

使用 Adob​​e 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
*/

关于php - navigateToURL 通过 POST 发送数据到 php 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11173762/

相关文章:

apache-flex - Flex 3,从服务器加载时无法将SystemManager转换为SystemManager吗?

actionscript-3 - AS3 - 如何复制 Sprite / Sprite 图形?

javascript - 如何在 PhantomJS 中使用 JavaScript 检测网页上的声音?

javascript - 从 javascript 接收字符串时 phpexplode() 不起作用

javascript - 使用ajax更新php页面使用post请求重新加载页面?

php - mustache 部分和代码重用

actionscript-3 - Flash AS3安全沙箱违规/s.ytimg.com

php - 如何启用 PHP Locale 类

actionscript-3 - 使用 Flex SDK 将 ActionScript 编译成 SWF

java - 在 3G 上闪存到 Java 套接字丢失数据包