0

I have to make a game for my thesis. I'm coding in ActionScript3. I have to use a service (REST interface). I've already read something about doing a GET.

How to access REST service in Actionscript 3?

Someone wrote that this code could be also use to do a POST, but how would the code change? How to do a POST from ActionScript3? Thank you in advance?

Community
  • 1
  • 1

3 Answers3

1

You just change the method of the URLRequest object. By default, it uses GET.

var l:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest( URL );
req.method = URLRequestMethod.POST; //this sets it to POST instead of GET
l.load( req );

See URLRequest.method in the LiveDocs

Josh
  • 8,079
  • 3
  • 24
  • 49
  • I would give you a point, but I have no reputation because I'm new! Thank you a lot! – GiorgiaGina Jul 27 '13 at 10:53
  • If this answered the question, you should mark it as correct (click the checkmark under the number) to close it. This will also help you build reputation and allow you to vote sooner – Josh Jul 27 '13 at 15:32
  • See [`URLRequest.data`](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#data) – Josh Aug 02 '13 at 16:00
0

Basically you configure the URLRequest differently:

var request = new URLRequest("http://localhost:3000/api/user/id");
request.method = URLRequestMethod.POST
loader.load(request);

see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#method for more.

Steve Allison
  • 1,091
  • 6
  • 6
0

The key is the URLRequest, and the method property. Leveraging from the example you referenced, modify the code to be

var req:URLRequest = new URLRequest("http://localhost:3000/api/user/id");
req.method = "POST"'
loader.load(req);
Bill Turner
  • 980
  • 1
  • 6
  • 23