| 包 | flash.net |
| 类 | public final class URLRequestHeader |
| 继承 | URLRequestHeader Object |
| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
requestHeaders 属性中使用。
在 Adobe® AIR 中,应用程序安全沙箱中的内容(如使用 AIR 应用程序安装的内容)可以使用任何请求标头而不会出错。不过,对于在 Adobe AIR 中运行的不同安全沙箱中的内容,使用以下请求标头将会引发运行时错误,且限制的术语不区分大小写(例如,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、Keep-Alive、Last-Modified、Location、Max-Forwards、Options、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 对象数组超过可接受的长度,则应用程序将引发异常。
除非为 URLRequest 类的 requestHeaders 属性中的 ACCEPT 标头指定设置,否则,在 Adobe AIR 中运行的内容会将 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 请求不提供相应支持。
另请参见
| 属性 | 定义方 | ||
|---|---|---|---|
![]() | constructor : Object
对类对象或给定对象实例的构造函数的引用。 | Object | |
| name : String HTTP 请求标头名称(例如 Content-Type 或 SOAPAction)。 | URLRequestHeader | ||
![]() | prototype : Object [静态]
对类或函数对象的原型对象的引用。 | Object | |
| value : String 与 name 属性相关联的值(如 text/plain)。 | URLRequestHeader | ||
| 方法 | 定义方 | ||
|---|---|---|---|
创建一个封装单个 HTTP 请求标头的新 URLRequestHeader 对象。 | URLRequestHeader | ||
![]() |
指示对象是否已经定义了指定的属性。 | Object | |
![]() |
指示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | |
![]() |
指示指定的属性是否存在、是否可枚举。 | Object | |
![]() |
设置循环操作动态属性的可用性。 | Object | |
![]() |
返回指定对象的字符串表示形式。 | Object | |
![]() |
返回指定对象的原始值。 | Object | |
| name | 属性 |
public var name:String| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
HTTP 请求标头名称(如 Content-Type 或 SOAPAction)。
| value | 属性 |
public var value:String| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
与 name 属性相关联的值(如 text/plain)。
| URLRequestHeader | () | 构造函数 |
public function URLRequestHeader(name:String = "", value:String = "")| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
创建一个封装单个 HTTP 请求标头的新 URLRequestHeader 对象。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 {
public function URLRequestHeaderExample() {
var loader:URLLoader = 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);
}
}
}