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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在Flex中使用HTTPService传递参数

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

先摘錄HTTPService的adobe關于MXML的官方內容如下:

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

注意:由于軟件限制,當使用 GET 時 HTTPService 不生成用戶界面友好的錯誤消息。

MXML 語法

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的語法傳參數時可以使用標記,需要放在fx:Declarations標簽里,例子如下:

<!-- 其余屬性的設置參見MXML 語法 -->

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

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

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

<s:request >

<!--參數名稱作標簽,中間填充參數值-->

<account>[account]</account>

<password>[password]</password>

</s:request>

</s:HTTPService>

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

<!-- 其余屬性的設置參見MXML 語法 -->

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,[結果處理方法,記得把事件傳過去]);

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

var parameter:URLVariables = new URLVariables();

parameter.account = [account];

parameter.password = [password];

service.send(parameter);

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

var parameter:URLVariables = new URLVariables();

parameter.account.system = [account];

parameter.password.system = [password];

運行時會報錯如下:

TypeError: Error #1010: 術語尚未定義,并且無任何屬性。

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]

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

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

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

1、escape,對0-255以外的unicode值進行編碼時輸出%u****格式。

2、encodeURI,將字符串編碼為有效的 URI(統一資源標識符)。將完整的 URI 轉換為一個字符串,其中除屬于一小組基本字符的字符外,其他所有字符都以 UTF-8?

轉義序列進行編碼。

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

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

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

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

encodeURIComponent是將中文、韓文等特殊字符轉換成utf-8格式的url編碼,所以如果給后臺傳遞參數需要使用encodeURIComponent時需要后臺解碼對utf-8支持。?

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。