navigateToURL通过POST发送数据到PHP页面 [英] navigateToURL sending data via POST to php page

查看:194
本文介绍了navigateToURL通过POST发送数据到PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我有两个字段,输入1和输入2 Flash应用程序的形式。当用户完成填补这一形式,它关系到一个PHP页面。 目前,我使用了 $ _ GET 方法发送数据。
像这样的:

Imagine that I have a form in a flash application with two fields, input1 and input2. And when the user finish filling this form, it goes to a php page. At the moment, I'm using the $_GET method to send the data.
Like this:

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

和在php code:

And in the php code:

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

但是这样一来,信息保持在URL中。我如何通过 $发送此_ POST

推荐答案

在AS 3中的用来说明您的需求的URLRequest 类有一个<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#method"相对=nofollow>方法属性,它可以用来设置自己的HTTP选项,提交方法,你需要将其设置为使用POST <一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequestMethod.html"相对=nofollow> URLRequestMethod 中恒<一href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequestMethod.html#POST"相对=nofollow> 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.

您可以找到一个 COM prehensive例如的上的 snipplr

You can find a comprehensive example on snipplr

所以简而言之:

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 类<一href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html#navigateToURL%28%29"相对=nofollow> navigateToURL()的原因主要有以下珍闻的:

When using Adobe Air You'd need to use the URLLoader class instead of navigateToURL() because of the following tidbit:

参数       要求:URLRequest - 一个URLRequest对象,指定要导航到的URL

Parameters request:URLRequest — A URLRequest object that specifies the URL to navigate to.

对于在Adobe AIR中运行的内容,使用navigateToURL()函数时,运行时将使用POST方法(一个设置为URLRequestMethod.POST其方法属性)作为使用GET方法<一个URLRequest / STRONG>

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设置方法一样,也通过为<一个文件指示href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html#navigateToURL%28%29"相对=nofollow> navigateToUrl :

Basically whenever you want to use POST set method correctly, as also indicated by the documentation for navigateToUrl:

接下来在PHP你会收到变量超全局 $彦博阵列,在那里你可以访问它,例如:

next in php you'd be receiving the variable in the superglobal $_POST array, where you could access it as such:

<?php
$foo = $_POST['foo'];
/* $foo now contains 'bar'
   assignment to another value is not necessary to use $_POST['foo'] 
   in any function or statement
*/

这篇关于navigateToURL通过POST发送数据到PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆