Good job! Glad you got it to work.
Kyle McKnight Senior UI Engineer - Accesso 602.515.1444 (M) On Tue, Jul 11, 2017 at 9:44 AM, Jeffry Houser <[email protected]> wrote: > Thanks Kyle and Javier for their thoughts. > > I was eventually able to do this using the lower level APIs of URLRequest > and URLLoader. I also had to manually create the parameter string. > Generically, the code is like this: > > > var parameters : String = ''; > parameters += "firstParameter=firstOne&"; > parameters += "amount=100&"; > parameters += "otherParameters=Other Random Misc Data&"; > parameters+= "lastParameter=LastOne"; > > > var r:URLRequest = new URLRequest(yourURLHere); > r.data = parameters; > r.method = URLRequestMethod.POST; > r.contentType = "application/x-www-form-urlencoded"; > > var l:URLLoader = new URLLoader(); > l.addEventListener(Event.COMPLETE, myResultMethod); > l.addEventListener(IOErrorEvent.IO_ERROR, myFailureMethod ); > l.addEventListener(SecurityErrorEvent.SECURITY_ERROR, myFailureMethod ); > l.load(r); > > Not as easy as using HTTPService, but functional and resolves this as > possible error cause when dealing with the vendor who built this API. > > Updated Stack Overflow Post: https://stackoverflow.com/ques > tions/44924870/can-i-control-the-parameter-order-in-an-httpservice-post > > My blog post on the issue: https://www.jeffryhouser.com/i > ndex.cfm/2017/7/11/How-can-I-control-the-parameter-order-whe > n-doing-a-HTTP-POST-call-from-Flex > > Thanks again! > > > On 7/5/2017 1:21 PM, Javier Guerrero García wrote: > >> Hi Jeffrey! >> >> My 4 cents :) >> >> 1. Maybe defining the <mx:request> inside the <mx:HTTPservice> >> declaration (and just binding the contents) helps somewhat. Maybe not, but >> at least it's prettier :) >> http://help.adobe.com/en_US/Flex/4.0/AccessingData/WS2db4549 >> 20e96a9e51e63e3d11c0bf69084-7fdc.html >> >> 2. Stupid one: try method="POST" (uppercase), just in case :) >> >> 3. According to the mx.rpc.httpAbstractOperation code, if >> typeof(parameters) == "object" it iterates and messes up with the order, >> but if it's not, it should just copy it to "paramsToSend" ("else >> paramsToSend=parameters;"). BUT, on some HTTP request implementations (for >> instance jQuery, not sure about flex), if you pass a string instead of a >> proper object as data, it "assumes" you want to make a GET instead of a >> POST. Are you 100% sure that, when you pass "parameters" as a string, you >> are issuing an empty *_POST_* request? >> >> 4. Instead of Flash network monitor, just get a quick PHP somewhere and >> monitor exactly what is arriving (and how) in your HTTP call (a simple >> <?php var_dump($_REQUEST); ?> would do). I'm not really sure if the sorting >> is done by the monitor itself, and I'm really perplexed about >> ObjectUtil.getClassInfo(parameters) does sort the object properties >> alphabetically (what a waste of CPU cycles!). >> >> >> P.S. And please, fire/kill the intern who programmed the server side >> trusting the order of the parameters.... I'm sure there is an RFC somewhere >> that you can throw at his face explicitly stating that params order should >> NOT be relevant when parsing an HTTP query string. >> >> >> On Tue, Jul 4, 2017 at 4:55 PM, Jeffry Houser <[email protected] >> <mailto:[email protected]>> 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 <tel:203-379-0773> >> >> >> > -- > Jeffry Houser > Technical Entrepreneur > http://www.dot-com-it.com > http://www.jeffryhouser.com > 203-379-0773 > >
