Highlighted

Creating JSON for REST service on PHP page

Participant ,
Mar 01, 2020

Copy link to clipboard

Copied

Hi,

This html code works to do what I want ie send 'abc_request' with JSON key 1234567. (btw I changed the key):

 

 

<form action="index.php" method="post"><textarea name="abc_request" class="form-control" >{"key":"1234567"}</textarea><button class="btn btn-primary" type="submit">POST</button></form>

 

 

How do I do that with Actionscript3;

 

So:

I am using var urlLoader:URLLoader;

I have urlRequest.method = URLRequestMethod.POST; working 

it is sending a request to the correct .php page

I just can't get the correct data format:

Best result I can get is using this:

 

 

var urlLoader:URLLoader;
var urlVariables:URLVariables = new URLVariables();
urlVariables.abc_request = {"key":"1234567"};
var url:String = "index.php";
var urlRequest:URLRequest = new URLRequest(url);
urlRequest.method = URLRequestMethod.POST;
urlRequest.data =urlVariables;
urlLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.load(urlRequest);

 

 

This is giving me a HTTPStatusEvent of 200 and 

a Bad Request echo from the php page meaning that it is receiving 'abc_request' but no key.

 

Any help appreciated.

 

Tommy Banana

 

 

By the way below

 

I Also TRIED:

 

var abc_request:Object = {"key":"1234567"};
var jsonString:String = JSON.stringify(abc_request);
urlRequest.data = jsonString;
urlLoader.load(urlRequest);

 

 

AND

 

 

var abc_request:Object = {"abc_request::{"key":"1234567"}};
var jsonString:String = JSON.stringify(abc_request);
urlRequest.data = jsonString;
urlLoader.load(urlRequest);
urlRequest.data =urlVariables;
urlVariables.abc_request = {"key":"1234567"};
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.load(urlRequest);

 

 

THEN TRIED:

 

 

var keyDEF:Object ={"key":"1234567"}
var jsonKey:String = JSON.stringify(keyDEF);
urlRequest.data =urlVariables;
urlVariables.abc_request = jsonKey;
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.load(urlRequest);

 

 

 

Tried all these; get either a No Request reply (meaning abc_request not submitted) or a bad request ( meaning after 'abc_request is received not receiving a key.

 

 

 

TOPICS
ActionScript, Code, Error, How to

Views

88

Likes

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

Creating JSON for REST service on PHP page

Participant ,
Mar 01, 2020

Copy link to clipboard

Copied

Hi,

This html code works to do what I want ie send 'abc_request' with JSON key 1234567. (btw I changed the key):

 

 

<form action="index.php" method="post"><textarea name="abc_request" class="form-control" >{"key":"1234567"}</textarea><button class="btn btn-primary" type="submit">POST</button></form>

 

 

How do I do that with Actionscript3;

 

So:

I am using var urlLoader:URLLoader;

I have urlRequest.method = URLRequestMethod.POST; working 

it is sending a request to the correct .php page

I just can't get the correct data format:

Best result I can get is using this:

 

 

var urlLoader:URLLoader;
var urlVariables:URLVariables = new URLVariables();
urlVariables.abc_request = {"key":"1234567"};
var url:String = "index.php";
var urlRequest:URLRequest = new URLRequest(url);
urlRequest.method = URLRequestMethod.POST;
urlRequest.data =urlVariables;
urlLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.load(urlRequest);

 

 

This is giving me a HTTPStatusEvent of 200 and 

a Bad Request echo from the php page meaning that it is receiving 'abc_request' but no key.

 

Any help appreciated.

 

Tommy Banana

 

 

By the way below

 

I Also TRIED:

 

var abc_request:Object = {"key":"1234567"};
var jsonString:String = JSON.stringify(abc_request);
urlRequest.data = jsonString;
urlLoader.load(urlRequest);

 

 

AND

 

 

var abc_request:Object = {"abc_request::{"key":"1234567"}};
var jsonString:String = JSON.stringify(abc_request);
urlRequest.data = jsonString;
urlLoader.load(urlRequest);
urlRequest.data =urlVariables;
urlVariables.abc_request = {"key":"1234567"};
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.load(urlRequest);

 

 

THEN TRIED:

 

 

var keyDEF:Object ={"key":"1234567"}
var jsonKey:String = JSON.stringify(keyDEF);
urlRequest.data =urlVariables;
urlVariables.abc_request = jsonKey;
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.load(urlRequest);

 

 

 

Tried all these; get either a No Request reply (meaning abc_request not submitted) or a bad request ( meaning after 'abc_request is received not receiving a key.

 

 

 

TOPICS
ActionScript, Code, Error, How to

Views

89

Likes

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
Mar 01, 2020 0

Have something to add?

Join the conversation