Send variables using POST

3

I am trying to open a new URL and send variables via POST method, but it only sends in GET method. I tried this Code:

// create a URLRequest object with the target URL:
var url : String = 'newpage.html';
var urlRequest : URLRequest = new URLRequest(url);

// create a URLVariables object and add all the values you want to send with their identifiers:
var urlVariables : URLVariables = new URLVariables();
urlVariables['formfieldId'] = 'formfieldValue';

// add the urlVariables to the urlRequest
urlRequest.data = urlVariables;

// set the method to post (default is GET)
urlRequest.method = URLRequestMethod.POST;

// use navigateToURL to send the urlRequest, use '_self' to open in the same window
navigateToURL(urlRequest, '_self');

I have this line urlRequest.method = URLRequestMethod.POST; but the URL does not open in the POST method only with GET method. What's wrong?

    
asked by anonymous 23.03.2014 / 20:51

2 answers

2

Unfortunately, if you are running an application on the Adobe AIR platform, you will not be able to send the values by POST method to the navigateToURL function because it will treat variables as GET according to Adobe's own documentation, found here .

If you are using the Flash Player platform on the web, I advise you to test the SWF file inside the same server domain with the code below:

SWF:

var url:String = "http://seudominio/teste.php";
var request:URLRequest = new URLRequest(url);
var urlloader:URLLoader = new URLLoader();
var variables:URLVariables = new URLVariables();

variables.valor = "VALOR DE TESTE";
request.data = variables;
request.method = URLRequestMethod.POST;

navigateToURL(request);

PHP:

<?php 

    $variavel = (isset($_POST["valor"]))?$_POST["valor"]:"erro";
    echo $variavel;

?>

If it works in the same domain and you need to put your swf in a different domain, check your server's security settings. More details here . p>

The tests I performed here worked correctly, even using a local server.

    
26.03.2014 / 15:14
0

This is because for content running in Adobe AIR, when using the navigateToURL () function, the runtime treats a URLRequest that uses the POST method (one with the method property set to URLRequestMethod.POST) through the GET method.

For example,

  public static const POST:String = "POST"

Put variable loader:

var loader:URLLoader = new URLLoader();

More information on this site ;

    
23.03.2014 / 21:52