日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

在Flex中使用HTTPService传递参数

發(fā)布時(shí)間:2024/9/20 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在Flex中使用HTTPService传递参数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

先摘錄HTTPService的adobe關(guān)于MXML的官方內(nèi)容如下:

在 MXML 文件中使用 <mx:HTTPService> 標(biāo)簽代表 HTTPService 對(duì)象。當(dāng)調(diào)用 HTTPService 對(duì)象的 send() 方法時(shí),將發(fā)出對(duì)指定 URL 的 HTTP 請(qǐng)求,并且返回 HTTP 響應(yīng)。可以選擇向指定 URL 傳遞參數(shù)。如果沒有使用基于服務(wù)器的代理服務(wù),則只能使用 HTTP GET 或 POST 方法。如果將 useProxy 屬性設(shè)置為 true 并使用基于服務(wù)器的代理服務(wù),則還可以使用 HTTP HEAD、OPTIONS、TRACE 和 DELETE 方法。

注意:由于軟件限制,當(dāng)使用 GET 時(shí) HTTPService 不生成用戶界面友好的錯(cuò)誤消息。

MXML 語(yǔ)法

The <mx:HTTPService> tag accepts the following tag attributes:

?<mx:HTTPService
?Properties
?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."
?Events
?fault="No default."
?result="No default."
?/>

?HTTPServiceExample.mxml

<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate the HTTPService tag. -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
???? xmlns:s="library://ns.adobe.com/flex/spark"
???? xmlns:mx="library://ns.adobe.com/flex/mx"
??? creationComplete="feedRequest.send();">
??????? <!-- The url property specifies the location of the requested file,
??????? in this case the RSS 2.0 feed of Matt Chotin's blog.
??????? As of this writing, the URL was still valid, but you should
??????? check to make sure it hasn't changed.
??????? You should use the latest RSS 2.0 URL listed on the right side of
??????? the blog at http://www.adobe.com/go/mchotinblog. -->
??? <fx:Declarations>
??????? <mx:HTTPService
??????????? id="feedRequest"
??????????? url="http://weblogs.macromedia.com/mchotin/index.xml"
??????????? useProxy="false" />
??? </fx:Declarations>
??? <mx:Panel title="HTTPService Example" height="75%" width="75%"
??????? paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
??????? <mx:DataGrid id="dgPosts" height="50%" width="75%"
??????????? dataProvider="{feedRequest.lastResult.rss.channel.item}">
??????????? <mx:columns>
??????????????? <mx:DataGridColumn headerText="Posts" dataField="title"/>
??????????????? <mx:DataGridColumn headerText="Date" dataField="pubDate"/>
??????????? </mx:columns>
??????? </mx:DataGrid>
??????? <mx:TextArea height="50%" width="75%" htmlText="{dgPosts.selectedItem.description}"/>
??? </mx:Panel>???
</s:Application>

源文檔 <http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/mx/rpc/http/mxml/HTTPService.html>

按照MXML的語(yǔ)法傳參數(shù)時(shí)可以使用標(biāo)記,需要放在fx:Declarations標(biāo)簽里,例子如下:

<!-- 其余屬性的設(shè)置參見MXML 語(yǔ)法 -->

<s:HTTPService id="service" url="[http://地址|https://地址]" method="POST" useProxy="false"

??????????? resultFormat="xml" fault="[失敗處理方法,記得把事件傳過去]"

??????????? result="[結(jié)果處理方法,記得把事件傳過去]">

<s:request >

<!--參數(shù)名稱作標(biāo)簽,中間填充參數(shù)值-->

<account>[account]</account>

<password>[password]</password>

</s:request>

</s:HTTPService>

也可以在ActionScript里使用對(duì)象的方式,例子如下:

<!-- 其余屬性的設(shè)置參見MXML 語(yǔ)法 -->

var service:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();

service.url = "[http://地址|https://地址]";

service.useProxy = false;

service.resultFormat="xml";

service.addEventListener(ResultEvent.RESULT,[結(jié)果處理方法,記得把事件傳過去]);

service.addEventListener(FaultEvent.FAULT,[失敗處理方法,記得把事件傳過去]);

var parameter:URLVariables = new URLVariables();

parameter.account = [account];

parameter.password = [password];

service.send(parameter);

在使用URLVariables時(shí)碰到一個(gè)問題,如果參數(shù)名本身就含有選擇符“.”,比如:

var parameter:URLVariables = new URLVariables();

parameter.account.system = [account];

parameter.password.system = [password];

運(yùn)行時(shí)會(huì)報(bào)錯(cuò)如下:

TypeError: Error #1010: 術(shù)語(yǔ)尚未定義,并且無任何屬性。

at com.adobe.sample::Sample/doLogonSubmit()[F:\[mxml路徑]\Sample.mxml:xx]

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]

at com.adobe.sample::LogonForm/validate()[F:\[mxml路徑]\LogonForm.mxml:xx]

at com.adobe.sample::LogonForm/__logonSubmit_click()[F:\[mxml路徑]\LogonForm.mxml:xx]

要傳遞帶選擇符的參數(shù),使用如下方法:

var parameter:Object = {"account.system":[account], "password.system": [password]};

好了,這里還要做的就是亂碼問題,對(duì)于中文這樣的多字節(jié)文字需要編碼后傳到服務(wù)器,編碼方式簡(jiǎn)單介紹如下:

1、escape,對(duì)0-255以外的unicode值進(jìn)行編碼時(shí)輸出%u****格式。

2、encodeURI,將字符串編碼為有效的 URI(統(tǒng)一資源標(biāo)識(shí)符)。將完整的 URI 轉(zhuǎn)換為一個(gè)字符串,其中除屬于一小組基本字符的字符外,其他所有字符都以 UTF-8?

轉(zhuǎn)義序列進(jìn)行編碼。

3、encodeURIComponent:將字符串編碼為有效的 URI 組件。將 URI 的子字符串轉(zhuǎn)換為一個(gè)字符串,其中除屬于非常小的一組基本字符的字符外,其他所有字符都以

UTF-8轉(zhuǎn)義序列進(jìn)行編碼。encodeURIComponent() 函數(shù)與 encodeURI() 函數(shù)不同,它僅適用于 URI 字符串的一部分(稱為 URI 組件)。URI 組件是指出現(xiàn)在某些特殊字符

之間的任何文本,這些特殊字符稱為組件分隔符(: / ; 和 ? )。“http”和“www.adobe.com”是常見的 URI 組件示例。

此函數(shù)與 encodeURI() 的另一個(gè)重要區(qū)別是:由于此函數(shù)假定它處理的是 URI 組件,因此它會(huì)將特殊分隔符字符 (; / ? : @ & = + $ , #) 視為應(yīng)進(jìn)行編碼的常規(guī)文本。

encodeURIComponent是將中文、韓文等特殊字符轉(zhuǎn)換成utf-8格式的url編碼,所以如果給后臺(tái)傳遞參數(shù)需要使用encodeURIComponent時(shí)需要后臺(tái)解碼對(duì)utf-8支持。?

具體采用哪種方式需要配合服務(wù)器端的解碼方式,如果服務(wù)器端的解碼方式已經(jīng)固定了,則還可以對(duì)編碼結(jié)果進(jìn)行替換等處理,如果服務(wù)器端的解碼方式還沒有那就隨便了。

總結(jié)

以上是生活随笔為你收集整理的在Flex中使用HTTPService传递参数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。