JW Blogs > Dustin’s Software Development Cogitations and Speculations >
A relatively infrequently encountered nuance of Flex 3's MXML/ActionScript's HTTPService that one may run into occurs when the HTTPService.method public property is set to "POST", but the server actually receives a GET HTTP method instead of the anticipated POST. As documented in Http Service Get vs Post Issue? IS this a bug? and HttpService Post Shows as Get on Server Logs, this occurs when the HTTPService with the method set to "POST" has its send method invoked without any parameters.
In the unlikely event that it is important to have the POST request treated as POST on the server despite having no parameters to pass, one can use a dummy parameter to cause this to happen. The remainder of this blog posting will focus on code examples of this.
The HTTPService can be declared as an MXML tag as shown next.
<mx:HTTPService id="httpService"
useProxy="false"
resultFormat="object"
url="http://localhost:8080/httpServer"
fault="faultHandler(event)"
result="resultHandler(event)" />
The HTTPService instance shown above can have its method set to HTTP POST and be invoked as shown in the next ActionScript snippet.
httpServiceProxied.method = "POST";
httpServiceProxied.send();
Although the method is clearly set to POST, if no parameters are passed, it will actually be treated like a GET instead of a POST. A dummy object can be added to force the POST to be treated like a POST as shown in the next ActionScript code snippet.
const dummyObject:Object = { "key" : "value" };
httpServiceProxied.method = "POST";
httpServiceProxied.send(dummyObject);
Using the dummy object as shown above will force the POST to be treated as a POST. Note that parameters for an HTTPService invocation can be specified not only in the send() method, but can also be specified in the HTTPService declaration with the <mx:request> element.
While it at first seems a little strange that a POST is treated as a GET if no parameter is supplied, it does not seem nearly as strange when one considers that an HTTP POST is designed to serve as a resource-changing method and a parameter (enclosed entity) will typically be associated with such functionality. Conversely, an HTTP GET is a safe and idempotent method designed for retrieval of data and is probably the more usual HTTP method of the two to be called when no parameter is specified.
Finally, it is worth noting here that when the proxied HTTPService is used (such as with BlazeDS), POST is used when the method is set to POST regardless of whether a parameter is included or not.
POST changed to GET
I can add another twist to this phenomenon. You have to pass a name/value pair as the param or else it will change to GET. I was passing an XML object by itself as the param object for a POST request and it was being changed into a GET request. Once I put my XML as a property on a generic object, the request stayed POST.
You can use an HTTPService
You can use an HTTPService component with any kind of server-side technology, including PHP pages, ColdFusion Pages, JavaServer Pages (JSPs), Java servlets, Ruby on Rails, and Microsoft ASP pages.
You can use a Flex
You can use a Flex HTTPService component in conjunction with PHP and a SQL database management system to display the results of a database query in a Flex application and to insert data into a database. Ray Ban Eyeglasses
You can call a PHP page with
You can call a PHP page with GET or POST to perform a database query. You can then format the query result data in an XML structure and return the XML structure to the Flex application in the HTTP response. ANZ Credit Card
watches replicareplica
watches replica
replica watch
Rolex Sea-Dweller replica
replica Franck Muller
oris watches
Rolex Day-Date II watches
Tag Heuer replica
Yachtmaster watch for sale
Post new comment