我遇到了 URLLoader/URLRequest 的一个非常奇怪的行为。看看下面的代码:
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;
if (params.action is ByteArray) {
params.action = Base64.encodeByteArray(params.action);
}
var vars:URLVariables = new URLVariables();
for (var paramName:String in params) {
vars[paramName] = params[paramName];
}
request.data = vars;
loader.load(request);
当我检查 HTTP 原始请求时,我看到:
POST /actions/send/3882-fba04fd1db5b0ac4f4107dd06632e851 HTTP/1.1
Host: domainname.com
Content-Length: 237
Origin: http://anotherdomain.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19
Content-Type: application/x-www-form-urlencoded
Accept: */*
Referer: http://anotherdomain.com/page.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: foo=bar
Pragma: no-cache
Cache-Control: no-cache
Content-type: application/x-www-form-urlencoded
Content-length: 165
action=BASE64DATABASE64DATABASE64DATABASE64DATABASE64DATABASE64DATABASE64DATA
所以.. wtf?为什么 URLLoader在标头\r\n
之后插入Cache-Control: no-cache
?试图找到解决方案,但没有任何运气。