Send variables using POST

Asked

Viewed 690 times

3

I am trying to open a new URL and send variables via method POST, but it only sends in method GET. I tried that 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 that line urlRequest.method = URLRequestMethod.POST; but the URL does not open in the method POST method-only GET. What’s wrong with it ?

  • Is the second site you want to open yours? Like navigateToURL treats variables only as GET, It may be interesting to use Sharedobject to create some cookies as an alternative.

2 answers

2

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

If you are using the Flash Player on the web, I advise you to perform the test with the SWF file within 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 on the same domain and you need to place your swf on a different domain, check your server’s security settings. More details here.

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

0

This is because For content running on Adobe AIR, when using the navigateToURL() function, Runtime treats a Urlrequest that uses the POST method (one with the method property defined as Urlrequestmethod.POST ) through the GET method.

For example,

  public static const POST:String = "POST"

Enter the variable Download:

var loader:URLLoader = new URLLoader();

On this website there is more information;

  • i want to open a new URL with variables in the POST method.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.