惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
Cloudbric
Cloudbric
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
博客园_首页
The Cloudflare Blog
C
Cisco Blogs
AWS News Blog
AWS News Blog
IT之家
IT之家
Cyberwarzone
Cyberwarzone
罗磊的独立博客
美团技术团队
V
V2EX
Project Zero
Project Zero
A
Arctic Wolf
C
Cyber Attacks, Cyber Crime and Cyber Security
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
S
Schneier on Security
P
Privacy International News Feed
V
Visual Studio Blog
量子位
T
Tor Project blog
S
Securelist
腾讯CDC
A
About on SuperTechFans
T
Threat Research - Cisco Blogs
G
GRAHAM CLULEY
B
Blog RSS Feed
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
B
Blog
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
V
Vulnerabilities – Threatpost
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
L
LINUX DO - 热门话题
Recorded Future
Recorded Future

博客园 - 晓光

Android获取手机短信 Android系统的进程,任务,服务的信息 Android程序如何安装到内存或卡中 (转)解决Debug certificate expired的问题 (转)Android ViewGroup的onInterceptTouchEvent()事件分析 (转)禁止横屏和竖屏切换 (转)Android Bitmap 与 Drawable之间的转换 (转)Android中两种设置全屏的方法 (转)Android之getSystemService (转)SQL Server Compact Edition 数据库连接字符串 (转)Android Project Structure (转)SqlDateTime溢出类错误解决 C# 数据库连接字符串集合 - 晓光 - 博客园 Android Activity生命周期 (转)Flex Module通信(2)——使用事件 (转)Flex Modules通信(1)——通过接口 (转)Canvas不能接收 rollOver和roolOut事件的解决方案 - 晓光 - 博客园 (转)FLEX中使用outerDocument - 晓光 - 博客园 (转)C# Hashtable Synchronized vs SyncRoot
Flex HttpService,WebService简单介绍
晓光 · 2010-11-02 · via 博客园 - 晓光

HttpService定义:
 在 MXML 文件中使用 <mx:HTTPService> 标签代表 HTTPService 对象。当调用 HTTPService 对象的 send() 方法时,
 将发出对指定 URL 的 HTTP 请求,并且返回 HTTP 响应。可以选择向指定 URL 传递参数。如果没有使用基于服务器的代理服务,
 则只能使用 HTTP GET 或 POST 方法。如果将 useProxy 属性设置为 true 并使用基于服务器的代理服务,则还可以使用
 HTTP HEAD、OPTIONS、TRACE 和 DELETE 方法。
 
 MXML 语法如下: 
 <mx:HTTPService
         concurrency="multiple|single|last"
         contentType="application/x-www-form-urlencoded|application/xml"
     destination="DefaultHTTP"
     id="No default."
     method="GET|POST|HEAD|OPTIONS|PUT|TRACE|DELETE"
     resultFormat="object|array|xml|e4x|flashvars|text"
     showBusyCursor="false|true"
    makeObjectsBindable="false|true"
    url="No default."
    useProxy="false|true"
    xmlEncode="No default."
    xmlDecode="No default."
    fault="No default."
    result="No default."
 />
 常用属性:
        id
    method
    resultFormat
    url
    useProxy
 常用事件:
    fault
      result
数据加载请求例子

 客户端:

通过标签来实现

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"
    creationComplete="application1_creationCompleteHandler(event)">
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   /**
    * 调用失败处理
    */
   protected function http_faultHandler(event:FaultEvent):void
   {
     Alert.show(event.fault.toString());
   }

   /**
    * 返回结果处理
    */
   protected function http_resultHandler(event:ResultEvent):void
   {
     Alert.show(event.result.toString());
   }

   /**
    * 初始化
    */
   protected function application1_creationCompleteHandler(event:FlexEvent):void
   {
      http.send();
   }

  ]]>
 </mx:Script>
 
 <mx:HTTPService id="http" resultFormat="array" method="POST" url="http://localhost:6196/Web/Default.aspx"
     useProxy="false" fault="http_faultHandler(event)" result="http_resultHandler(event)"/>
</mx:Application>

通过代码来实现

   /**
    * 调用失败处理
    */
   protected function http_faultHandler(event:FaultEvent):void
   {
    Alert.show(event.fault.toString());
   }

   /**
    * 返回结果处理
    */
   protected function http_resultHandler(event:ResultEvent):void
   {
    Alert.show(event.result.toString());
   }

   /**
    * 初始化
    */
   protected function application1_creationCompleteHandler(event:FlexEvent):void
   {
    var service:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
    service.url = "http://localhost:6196/Web/Default.aspx";
    service.useProxy = false;
    service.resultFormat="text";
    service.addEventListener(ResultEvent.RESULT,http_resultHandler);
    service.addEventListener(FaultEvent.FAULT,http_resultHandler);
    service.send();
   }

服务端:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Hello Flex HttpService");
    }

 参数传递方式共两种

客户端

第一种

/**
    * 调用失败处理
    */
   protected function http_faultHandler(event:FaultEvent):void
   {
    Alert.show(event.fault.toString());
   }

   /**
    * 返回结果处理
    */
   protected function http_resultHandler(event:ResultEvent):void
   {
    Alert.show(event.result.toString());
   }

   /**
    * 初始化
    */
   protected function application1_creationCompleteHandler(event:FlexEvent):void
   {
    var service:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
    service.url = "http://localhost:6196/Web/Default.aspx?a=yang&b=xiao";
    service.useProxy = false;
    service.resultFormat="text";
    service.addEventListener(ResultEvent.RESULT,http_resultHandler);
    service.addEventListener(FaultEvent.FAULT,http_resultHandler);
    service.send();
   }

第二种

/**
    * 调用失败处理
    */
   protected function http_faultHandler(event:FaultEvent):void
   {
    Alert.show(event.fault.toString());
   }

   /**
    * 返回结果处理
    */
   protected function http_resultHandler(event:ResultEvent):void
   {
    Alert.show(event.result.toString());
   }

   /**
    * 初始化
    */
   protected function application1_creationCompleteHandler(event:FlexEvent):void
   {
    var service:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
    service.url = "http://localhost:6196/Web/Default.aspx";
    service.useProxy = false;
    service.resultFormat="text";
    service.addEventListener(ResultEvent.RESULT,http_resultHandler);
    service.addEventListener(FaultEvent.FAULT,http_resultHandler);
    var param:URLVariables = new URLVariables();
    param.a = "yang";
    param.b = "xiao";
    service.send(param);
   }

服务端

 public string A
    {
        get
        {
            object o = Request.QueryString["a"];
            if (o == null)
            {
                return "";
            }
            return o.ToString();
        }
    }
    public string B
    {
        get
        {
            object o = Request.QueryString["b"];
            if (o == null)
            {
                return "";
            }
            return o.ToString();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Hello Flex HttpService\r\n");
        Response.Write(A + "\r\n");
        Response.Write(B + "\r\n");
    }

 返回的数据类型