Hey Jeffry:

I may be missing something in my understanding of your problem, but are you 
trying to send a body of parameters in the request payload? If so, I suggest 
you adopt a JSON or plain text approach, and build your params into the 
body/payload in the order you want by just building the string:

// JSON approach
httpService.contentType = "application/json";
httpService.send({ \"otherParameters\": \"Other Random Misc Data\", 
\"lastParameter\": \"LastOne\", \"firstParameter\": \"firstOne\", \"amount\": 
100 });

The server endpoint will of course need to know how to parse the JSON, but your 
order will be preserved in the body of the request.

Another approach could be just to send the entire parameter string as you want 
it as the payload/body by just directly assigning it:

httpService.contentType = "text/html";
httpService.send("otherParameters=Other Random Misc 
Data&lastParameter=LastOne&firstParameter=firstOne&amount=100");

And parse the params on the server.

I so often have to bypass some of the cool functionality Flex provides to save 
me code when dealing with REST communication but with HTTP communication, 
everything is possible, since in the end an HTTP request is an HTTP request, 
it's generic, and unless your server cannot be changed to deal with a generic 
HTTP request (just treat the payload/body however you want) you can do anything 
you want by just building your requests without depending on utility classes. 
Sure you may have to write 5 more lines of code on the server, but that's often 
a lot easier than trying to fix something Flex doesn't do for you OOTB.

Erik

> On Jul 4, 2017, at 7:55 AM, Jeffry Houser <jef...@dot-com-it.com> wrote:
> 
> Hi Everyone,
> 
>  I'm updating a Point of Sale system that was built with Flex and AIR using 
> the Cairngorm framework.
> 
> The code integrates with a custom server provided by my client's payment 
> processor vendor.  Part of their requirement is that parameters be form 
> posted to their server in a specific order. The Apache Flex framework does 
> not appear to retain the parameter order of the object's parameters.  Has 
> anyone run into this before?
> 
> More specifics, with code:
> 
> 1) Service object set up in the Cairngorm Services.mxml:
> 
>    <mx:HTTPService id="service"
>                    showBusyCursor="false"
>                    requestTimeout="240"
>                    method="post" 
> contentType="application/x-www-form-urlencoded"
>                    url="http://localhost.:16448/"; resultFormat="e4x"
>                    />
> 
> 2) Create Parameter object and call service method; this is done in a 
> Cairngorm Delegate:
> 
> var parameters : Object = new Object();
> parameters.firstParameter  = "firstOne";
> parameters .amount = 100;
> parameters .otherParameters = "Other Random Misc Data";
> parameters.lastParameter = "LastOne";
> 
> Then make the call:
> 
> var call : Object    = this.service.send(parameters);
> call.addResponder( this.responder );
> 
> 3) Flex Framework class mx.rpc.httpAbstractOperation, starting around line 
> 862.  This appears to loop over properties using classinfo.properties .  This 
> seems to get an alphabetical list of properties from my object and add them 
> to the paramsToSend object:
> 
> 
>        else if (ctype == CONTENT_TYPE_FORM)
>        {
>            paramsToSend = {};
>            var val:Object;
> 
>            if (typeof(parameters) == "object")
>            {
>                //get all dynamic and all concrete properties from the 
> parameters object
>                var classinfo:Object = ObjectUtil.getClassInfo(parameters);
> 
>                for each (var p:* in classinfo.properties)
>                {
>                    val = parameters[p];
>                    if (val != null)
>                    {
>                        if (val is Array)
>                            paramsToSend[p] = val;
>                        else
>                            paramsToSend[p] = val.toString();
>                    }
>                }
>            }
>            else
>            {
>                paramsToSend = parameters;
>            }
>        }
> 
> 4) Looking at the raw data in the Flash Builder Network Monitor; the final 
> request doesn't have the parameters in alphabetical order.
> 
> otherParameters=Other%20Random%20Misc%20Data&lastParameter=LastOne&firstParameter=firstOne&amount=100
> 
>  With this small sample it appears that the parameters are in reverse 
> alphabetical order, but with the actual request data they are in a seemingly 
> random--but always consistent--order.
> 
> 
> -------
> 
> Thanks for reading this far.  My first attempt at a solution was to create 
> the POST parameter string manually and use that as the parameter object.  
> However in that case the body of the POST request was blank when reviewing it 
> in the service monitor.
> 
>  So, has anyone run into this before?  What was your solution?
> 
> 
> 
> -- 
> 
> Jeffry Houser
> Technical Entrepreneur
> http://www.dot-com-it.com
> http://www.jeffryhouser.com
> 203-379-0773
> 
> 

Reply via email to