`

Flex FileReference URLRequest 请求缓存问题

    博客分类:
  • Flex
 
阅读更多

   

    UrlRequest请求时会缓存会话,也就是说当URL路径不改变,但指定的文件已经进行内容修改,客户端请求的结果还是最先访问产生的会话缓存,如何解决这个问题呢?

 

    可以想到的是每次URL路径发生改变,Get方式时后面添加参数,Post方式提交不断变换的参数进而产生URL每次不同的效果,其实两种方式就是改变参数的不同。

 

    Get:http://****/file/test.txt?random=唯一值

    Post:

    

var variables:URLVariables = new URLVariables();

variables.rannum = Math.random();

var url:String = 文件地址

var request:URLRequest = new URLRequest(encodeURL(uri));

request.data = variables;

request.method =  URLRequestMethod.POST;

 

 

    另附完整代码

    

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 
	<mx:Script>
		<![CDATA[
			
			import mx.utils.UIDUtil;
  			
  			[Bindable]
  			public var file:FileReference;
     		private var currentAction:String;
     		private var downloadURL:URLRequest;
 		
 			private function download():void{  
     
     			var url:URLRequest=new URLRequest("http://localhost:8080/FlexMessageServer/test.txt");
     			url.method = URLRequestMethod.POST;
     			url.data = UIDUtil.createUID();
     			file = new FileReference();
      			file.addEventListener(Event.COMPLETE,comple) 
      			file.download(url)
		
     		}
     
		    private function comple(e:Event):void
		    {
		    	tex.text="已下载完成!"
		    }

  ]]>
 </mx:Script>
 
 <mx:Button  x="10" y="20" label="下载一个文件" click="download()"/>
 <mx:ProgressBar x="10" y="100" id="progress" source="{file}" label="已加载: %3%%"/>
 <mx:Text text="" x="10" y="145" id="tex"/>

</mx:Application>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics