• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AS3 POST to PHP - help needed.

Participant ,
Feb 29, 2020 Feb 29, 2020

Copy link to clipboard

Copied

I am new to talking to PHP.

 

Trying to test sending data to a .php page both on a localhost server and on a remote server

 

I am trying following code:

 

AS3:

 var myData:URLRequest = new URLRequest("http://127.0.0.1:8080/testtom.php");
var variables:URLVariables = new URLVariables();
variables.username = "abc_request";
variables.amount = "5";
myData.data = variables;
myData.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
//loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.load(myData);
 
 
function dataOnLoad(evt:Event){
    trace('Completed');
}
function httpStatusHandler(event:HTTPStatusEvent){
results_txt.text = "httpStatusHandler: " + event;
result2_txt.text ="status: " + event.status
    }
 
PHP:

<?php

echo $_POST["username"]."post";
echo $_POST["amount"]."post";
echo $_GET["username"]."get";
echo $_GET["amount"]."get";

echo "hello world 808080";
?>

 

When sending to the localhost server I am getting an HTTPStatus of 200 back - suggesting something is working.

If I set loader.dataFormat = URLLoaderDataFormat.TEXT;  to URLLoaderDataFormat.VARIABLES

I get an error:

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.

 

which suggests that when I use URLLoaderDataFormat.TEXT; that the data is being sent.

However I can't get the .php page to update.

 

Any help greatly appreciated.

 

Best Tommy Banana

 

 

TOPICS
ActionScript , Code , Error , How to

Views

466

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 29, 2020 Feb 29, 2020

Copy link to clipboard

Copied

So we have tested the .PHP page and it works fine receiving a GET message from html.

eg clicking on the link 

 ourserver/testtom.php?username=TESTUSER&amount=123

gets the variables displayed on the php page in the GET section using the php code above.

So the problem is in getting the .swf file to talk to the .php correctly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 01, 2020 Mar 01, 2020

Copy link to clipboard

Copied

So in case anyone else ends up here. This code worked:

 

https://tournasdimitrios1.wordpress.com/2010/09/18/two-way-communication-between-flash-and-php-excha...

 

So now I have the POST method working from AS3 to PHP and getting data back I can now try and work out how

to build the thing I need.... using JSON!

 

NB For it to work I needed to have both the .php and .swf file in the same directory online and not to use an absolute URL.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 01, 2020 Mar 01, 2020

Copy link to clipboard

Copied

LATEST

I tell a lie - it does work with an absolute URL!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines