With HTTPService, your client application can send traditional HTTP requests to a server and consume the response. Although you can use HTTPService to consume different types of responses, you typically use it to consume XML (XML over HTTP). You can use the HTTPService to send requests to any kind of back-end system: JSP, Servlet, ASP, ColdFustion, CGI, PHP, and so forth.
In this lab, you use the HTTPService to retrieve the list of restaurants. The HTTPService sends a request to a JSP, which returns the list of restaurants as an XML document.
Note: [webapp_root] is the root directory of the web application hosting the Flex server you are using. For example, if you chose the Integrated Server installation, the webapp_root is Program Files\Macromedia\Flex\jrun4\servers\default\flex
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"> </mx:Application>
<mx:HTTPService id="srv" url="restaurantlist.jsp"/>
<mx:Button label="Get Data" click="srv.send()"/>
<mx:DataGrid id="dg" dataProvider="{srv.result.list.restaurant}" widthFlex="1" heightFlex="1"/>
Note: Notice that srv.result points to the response of the HTTP request, while list and restaurant correspond to the nodes in the XML document you navigate through (see restaurantlist.jsp).
Test the application: http://localhost:8700/flex/restaurant/restaurant1.mxml
If you haven't already modified the HTTPService whitelist, the following error message appears:

Figure 5. This error message appears if you have not modified the whitelist
This is because you have installed Flex with strict security constraints by default. To allow your application to access this HTTPservice, you must edit the HTTPService whitelist as described in the following steps.
<http-service-proxy> entryAdd the http://{localserver}/* URL to the unnamed whitelist.
<http-service-proxy>
<!-- Other entries -->
<whitelist>
<unnamed>
<url>http://{localserver}/*</url>
</unnamed>
By setting this, the client application can access any URL on the server from where the application was downloaded.
Test the application again.
http://localhost:8700/flex/restaurant/restaurant1.mxml
<mx:DataGrid id="dg" dataProvider="{srv.result.list.restaurant}" widthFlex="1" heightFlex="1">
<mx:columns>
<mx:Array>
<mx:DataGridColumn columnName="name" headerText="Name"/>
<mx:DataGridColumn columnName="city" headerText="City"/>
<mx:DataGridColumn columnName="phone" headerText="Phone"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
<mx:Panel title="Restaurant List"> <!-- DataGrid Here --> <mx:ControlBar> <mx:Button label="Get Data" click="srv.send()"/> </mx:ControlBar> </mx:Panel>