一开始,我想有一个服务器端脚本,通过传递一个var来加载图像(比如通过PHP),这个var可以被解密,但是有一个动态salt,比如,使用一个不太可能被发现的方法(比如,将salt嵌入整个字符串),但是这会破坏CDN的目的,因为所有请求都会被定位到服务器。
然后我认为通过套接字加载图像将是一个很好的解决方案,但是,我在将二进制图像(在删除响应头之后)转换为位图时遇到了问题。
有没有更好的办法?我知道,现实上是不可能完全阻止内容被链接到(如有人可以截屏的闪光),但我的目标只是采取措施,在我们这边,以防止发生这种事情的本地手段。如有任何想法,我们将不胜感激。下面是套接字代码(删除了不相关的部分),如果这有帮助的话。
package com.std.socket {
import flash.system.Security;
import flash.net.Socket;
import flash.events.*;
import flash.errors.*;
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.utils.ByteArray;
public class SocketRequest {
private var root:MovieClip;
private var sock:Socket;
private var data:ByteArray = new ByteArray();
private var request:Object = {
'host': null,
'port': null,
'uri': null,
'callback': null,
'response_parts': [] };
public function SocketRequest(root:MovieClip, host:String, port:int, uri:String, callback:Function):void {
Security.allowDomain('*');
Security.loadPolicyFile('http://foo.bar/crossdomain.xml');
this.request.root = root;
this.request.host = host;
this.request.port = port;
this.request.uri = uri;
this.sock = new Socket();
this.sock.addEventListener(Event.CONNECT, this.evt_socketConnect);
this.sock.addEventListener(Event.CLOSE, this.evt_socketClose);
this.sock.addEventListener(ProgressEvent.SOCKET_DATA, this.evt_socketResponse);
this.sock.connect(this.request.host, this.request.port);
}
private function evt_socketConnect(evt:Event):void {
// Send the request headers
this.sock.writeUTFBytes('GET ' + this.request.uri + " HTTP/1.1\n");
this.sock.writeUTFBytes('Host: ' + this.request.host + ':' + this.request.port + "\n\n");
}
private function evt_socketClose(evt:Event):void {
// Since this is an image, just split on header \r\n and get the last member
var response:Array = this.request.response_parts.join('').split("\r\n");
var body:String = response[response.length - 1];
var loader = new Loader();
var ba:ByteArray = new ByteArray();
var mc:MovieClip = new MovieClip();
this.data.writeMultiByte(body, 'utf-8');
loader.loadBytes(this.data);
mc.addChild(loader);
// Pass the resulting MovieClip back to the caller
if(typeof(this.request.callback) == 'function')
this.request.callback.apply(this.request.root, [mc])
}
private function evt_socketResponse(evt:ProgressEvent):void {
if(!this.sock.bytesAvailable)
return;
this.request.response_parts.push(this.sock.readUTFBytes(this.sock.bytesAvailable));
}
}
}
在我写作的时候我在想
SocketRequest::evt_socketResponse()
,的
this.sock.readUTFBytes()
比特应该是:
this.request.response_parts.push(this.sock.readBytes(this.data, this.data.length, evt.bytesLoaded));
然后从
this.data