Another name for HTTP Service is REST style web service. To make a successful web service call we gotta take care of steps as below. Similar steps apply for HTTP Object instantiated via HTTP service tag.
1) Instantiate the HTTPService Object.
var httpService: HTTPService = new HTTPService();
2) Set the URL
httpService.url = "serviceURL"; //Mention the service URL
3) Set the method type [GET/POST/PUT/DELETE], default is GET
httpService.method = HTTPService.POST;
4) Set the resultFormat to XML [for true REST], default is Object
httpService.resultFormat = "xml"; //Values possible are object, xml, e4x, text, array, flashvars
5) Add result and fault event listeners
httpService.addEventListener("result", httpResultHandler);
httpService.addEventListener("fault", httpFaultHandler);
6) Construct the parameters to be passed if any, default is null. For example if
your service expects two parameters "userID" & "userName", the values of which you wanna pass as userIDValue and userNameValue, construct an object:
var serviceParameters: Object = {};
serviceParameters["userID"] = userIDValue;
serviceParameters["userName"] = userNameValue;
7) Make the call
httpService.send(serviceParameters);
Bingo! Have Fun! :)
Thursday, February 18, 2010
Subscribe to:
Post Comments (Atom)
please guide.
ReplyDeleteHow to cancel a httpService.send(obj);
i have already tried httpService.cancel() but it doesn't work.
Thanks with regards,
Adarsh