| 套件 | flash.net |
| 類別 | public final class URLRequestMethod |
| 繼承 | URLRequestMethod Object |
| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
POST 方法或 GET 方法。
相關 API 元素
公用常數
| 常數 | 定義自 | ||
|---|---|---|---|
| DELETE : String = "DELETE" [靜態]
指定 URLRequest 物件為 DELETE。 | URLRequestMethod | ||
| GET : String = "GET" [靜態]
指定 URLRequest 物件為 GET。 | URLRequestMethod | ||
| HEAD : String = "HEAD" [靜態]
指定 URLRequest 物件為 HEAD。 | URLRequestMethod | ||
| OPTIONS : String = "OPTIONS" [靜態]
指定 URLRequest 物件為 OPTIONS。 | URLRequestMethod | ||
| POST : String = "POST" [靜態]
指定 URLRequest 物件為 POST。 | URLRequestMethod | ||
| PUT : String = "PUT" [靜態]
指定 URLRequest 物件為 PUT。 | URLRequestMethod | ||
常數詳細資訊
DELETE | 常數 |
public static const DELETE:String = "DELETE"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0 |
指定 URLRequest 物件為 DELETE。
GET | 常數 |
public static const GET:String = "GET"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
會指定 URLRequest 物件為 GET。
HEAD | 常數 |
public static const HEAD:String = "HEAD"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0 |
指定 URLRequest 物件為 HEAD。
OPTIONS | 常數 |
public static const OPTIONS:String = "OPTIONS"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0 |
指定 URLRequest 物件為 OPTIONS。
POST | 常數 |
public static const POST:String = "POST"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
會指定 URLRequest 物件為 POST。
注意:針對 Adobe AIR 中執行的內容,當您使用 navigateToURL() 函數時,執行階段會將使用 POST 方法的 URLRequest (其 method 屬性設為 URLRequestMethod.POST 者) 視同使用 GET 方法的物件。
PUT | 常數 |
範例 如何使用本範例
URLRequestMethodExample.as
下列範例會載入並顯示在本機文字檔案中找到的資料。 此外,它也會追蹤事件處理資訊。
注意: 如果要執行這個範例,請將 example.txt 這個檔案放入與您 SWF 檔相同的目錄中。 該檔案是包含幾個字或幾行字的簡單文字檔。
此範例程式碼會執行下列動作:
- 建構函數會建立名為
loader的 URLLoader 實體。 - 將
loader物件傳遞給configureListeners()方法後,再將偵聽程式加入每一個支援的 URLLoader 事件。 - 然後建立名為
request的 URLRequest 實體,該實體會指定要載入的檔案名稱。 - 該要求的
method屬性會設定為URLRequestMethod.POST。 - 然後將
request物件傳遞給loader.load()方法,以便載入文字檔。 - 當 URLLoader 完成文字檔的載入作業時,就會引發
Event.COMPLETE事件,並觸發completeHandler()方法。completeHandler()方法只會追蹤data屬性,也就是文字檔的內容。
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
public class URLRequestMethodExample extends Sprite {
private var loader:URLLoader;
public function URLRequestMethodExample() {
loader = new URLLoader();
configureListeners(loader);
var request:URLRequest = new URLRequest("example.txt");
request.method = URLRequestMethod.POST;
loader.load(request);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
private function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
}
private function openHandler(event:Event):void {
trace("openHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
}
}
Tue Jun 12 2018, 03:47 PM Z
隱藏繼承公用屬性
顯示繼承公用屬性