HttpService 使用useProxy参数

 

If you want your application to access services available on another domain without deploying a crossdomain.xml file on that domain (for example, because you may not own the target domain), you can set the useProxy attribute of the HTTPService to "true" like in this example. In this case, the request is sent to the BlazeDS proxy which makes the request to the target domain on the client application's behalf. This configuration also provides more control over the access to the service. For example, you may configure the proxy to require authentication before accessing a service, log access to the service, etc.

When using the proxy, you can specify a logical name in the HTTPService destination attribute instead of specifying a hardcoded value in the url attribute. You then map this logical name to an actual URL in WEB-INF/flex/proxy-config.xml. Open WEB-INF/flex/proxy-config.xml to see how the catalog destination is configured.

 

优点:

1. 可以跨域

2. 可以在这里做一些认证登陆等操作

3. 避免在mx:HttpService中使用url硬编码

 

代码示例

main.mxml

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF"> <mx:HTTPService id="srv" destination="catalog" useProxy="true"/> <mx:DataGrid dataProvider="{srv.lastResult.catalog.product}" width="100%" height="100%"/> <mx:Button label="Get Data" click="srv.send()"/> </mx:Application>

 

flex/proxy-config.xml

<destination id="catalog"> <properties> <url>/{context.root}/testdrive-httpservice/catalog.jsp</url> </properties> </destination>

 

 

 

你可能感兴趣的:(HttpService 使用useProxy参数)