权限验证:
var fileRef:FileReference = new FileReference();
var request:URLRequest = new URLRequest(serviceUrl);
request.method = URLRequestMethod.POST;
var encoder : Base64Encoder = new Base64Encoder();
encoder.encode(userName + ":" + password);
request.requestHeaders.push(new URLRequestHeader("Authorization", "Basic " + encoder.toString())); // ** 增加认证信息
fileRef.addEventListener(Event.OPEN, onFileDownloadBegin);
fileRef.addEventListener(Event.COMPLETE, onFileDownloadComplete);
fileRef.addEventListener(IOErrorEvent.IO_ERROR, onFileDownloadError);
fileRef.addEventListener(Event.CANCEL, onFileDownLoadCancel);
fileRef.download(request, getExportFileName(serviceUrl));
使用URLRequest下载文件. – 无权限认证
// 下载文件
protected function downloadTemplateFile():void {
var fileRef:FileReference = new FileReference();
var urlReq:URLRequest = new URLRequest(_pathTemplateFile);
fileRef.addEventListener(Event.OPEN,onDownloadBegin);
fileRef.addEventListener(Event.COMPLETE, onDownloadComplete);
fileRef.addEventListener(Event.CANCEL, onDownloadCancel);
fileRef.addEventListener(IOErrorEvent.IO_ERROR, onDownloadError);
fileRef.download(urlReq);
}
// 模板文件下载开始时响应.
protected function onDownloadBegin(e:Event):void {
appendTextToOutPut(RM.getString(BUNDLE_ASMT_MGT, "template.download.begin"));
}
// 当下载结束后响应. */
protected function onDownloadComplete(e:Event):void {
var file:FileReference = e.target as FileReference;
appendTextToOutPut(RM.getString(BUNDLE_ASMT_MGT, "template.download.success", [file.name, FileUtils.formatFileSize(file.size)]));
log.info("模板文件下载结束: " + file.name + "-" + file.size);
}
// 当下载取消时响应. */
protected function onDownloadCancel(e:Event):void {
appendTextToOutPut(RM.getString(BUNDLE_ASMT_MGT, "controller.download.canceled"));
}
// 当下载出现错误时响应. */
protected function onDownloadError(e:IOError):void {
appendTextToOutPut(RM.getString(BUNDLE_ASMT_MGT, "template.download.error", [...]
最新的三6条正面评论