| 套件 | flash.net |
| 類別 | public final class URLRequestHeader |
| 繼承 | URLRequestHeader Object |
| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
requestHeaders 屬性中使用。
在 Adobe® AIR® 中,應用程式安全執行程序中的內容 (例如以 AIR 應用程式安裝的內容) 可以使用任何要求標頭,不會有錯誤。不過,對於不同安全執行程序中的 Adobe AIR 執行內容,或在 Flash® Player 中執行的內容,使用下列要求標頭會擲出執行階段錯誤,而且限制的項目不會區分大小寫 (例如,Get、get 和 GET 都不被允許):
在 Flash Player 中以及在應用程式安全執行程序外的 Adobe AIR 內容中,下列要求標頭都無法使用,而且限制的項目也不會區分大小寫 (例如,Get、get 和 GET 都不被允許)。此外,如果使用底線字元,則使用連字符號的術語也適用 (例如,Content-Length 和 Content_Length 都不被允許):
Accept-Charset、Accept-Encoding、Accept-Ranges、Age、Allow、Allowed、Authorization、Charge-To、Connect、Connection、Content-Length、Content-Location、Content-Range、Cookie、Date、Delete、ETag、Expect、Get、Head、Host、If-Modified-Since、Keep-Alive、Last-Modified、Location、Max-Forwards、Options、Origin、Post、Proxy-Authenticate、Proxy-Authorization、Proxy-Connection、Public、Put、Range、Referer、Request-Range、Retry-After、Server、TE、Trace、Trailer、Transfer-Encoding、Upgrade、URI、User-Agent、Vary、Via、Warning、WWW-Authenticate、x-flash-version。
URLRequestHeader 物件都會具有長度上的限制。 如果 URLRequestHeader 物件的累計長度 (name 屬性加上 value 屬性的長度) 或 URLRequest.requestHeaders 屬性中使用之 URLRequestHeader 物件陣列的累計長度超過可接受的長度,就會擲出例外。
Adobe AIR 中執行的內容會將 ACCEPT 標頭設定為如下列所示,除非您在 URLRequest 類別的 requestHeaders 屬性中指定 ACCEPT 標頭的設定值:
text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, image/png, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, */*;q=0.5
並非所有接受 URLRequest 參數的方法都會支援 requestHeaders 屬性;請參閱您要呼叫之方法的文件。例如,FileReference.upload() 和 FileReference.download() 方法不支援 URLRequest.requestHeaders 屬性。
由於瀏覽器的限制,只有 POST 要求會支援自訂 HTTP 要求檔頭,GET 要求並不支援。
相關 API 元素
| 屬性 | 定義自 | ||
|---|---|---|---|
![]() | constructor : Object
類別物件的參照或是特定物件實體的建構函數。 | Object | |
| name : String
HTTP 要求檔頭名稱 (例如 Content-Type 或 SOAPAction)。 | URLRequestHeader | ||
| value : String
與 name 屬性相關聯的值 (例如 text/plain)。 | URLRequestHeader | ||
| 方法 | 定義自 | ||
|---|---|---|---|
會建立新的 URLRequestHeader 物件 (會封裝單一 HTTP 要求檔頭)。 | URLRequestHeader | ||
![]() |
指出物件是否有已定義的指定屬性。 | Object | |
![]() |
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。 | Object | |
![]() |
指出指定的屬性是否存在,以及是否可列舉。 | Object | |
![]() |
為迴圈作業設定動態屬性的可用性。 | Object | |
![]() |
傳回代表此物件的字串,根據地區特定慣例進行格式化。 | Object | |
![]() |
會傳回指定之物件的字串形式。 | Object | |
![]() |
會傳回指定之物件的基本值。 | Object | |
name | 屬性 |
public var name:String| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
HTTP 要求檔頭名稱 (例如 Content-Type 或 SOAPAction)。
value | 屬性 |
public var value:String| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
與 name 屬性相關聯的值 (例如 text/plain)。
URLRequestHeader | () | 建構函式 |
public function URLRequestHeader(name:String = "", value:String = "")| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
會建立新的 URLRequestHeader 物件 (會封裝單一 HTTP 要求檔頭)。 URLRequestHeader 物件是在 URLRequest 類別的 requestHeaders 屬性中使用。
name:String (default = "") — HTTP 要求檔頭名稱 (例如 Content-Type 或 SOAPAction)。
| |
value:String (default = "") — 與 name 屬性相關聯的值 (例如 text/plain)。
|
header 加入 requestHeaders 屬性的陣列。 即使有正進行要求的快取副本,檔頭也會指出應用程式應該將要求轉寄至原始伺服器。
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
public class URLRequestHeaderExample extends Sprite {
private var loader:URLLoader;
public function URLRequestHeaderExample() {
loader = new URLLoader();
configureListeners(loader);
var header:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
var request:URLRequest = new URLRequest("http://www.[yourdomain].com/greeting.cfm");
request.data = new URLVariables("name=John+Doe");
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
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
隱藏繼承公用屬性
顯示繼承公用屬性