WebRequest 忽略缓存

publicstaticWebResponseGetResponseNoCache(Uri uri)
{
       
// Set a default policy level for the "http:" and "https" schemes.
       
HttpRequestCachePolicy policy =newHttpRequestCachePolicy(HttpRequestCacheLevel.Default);
       
HttpWebRequest.DefaultCachePolicy= policy;
       
// Create the request.
       
WebRequest request =WebRequest.Create(uri);
       
// Define a cache policy for this request only.
       
HttpRequestCachePolicy noCachePolicy =newHttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
        request
.CachePolicy= noCachePolicy;
       
WebResponse response = request.GetResponse();
       
Console.WriteLine("IsFromCache? {0}", response.IsFromCache);            
       
return response;
}
posted @ 2012-04-21 22:32  把爱延续  阅读(1840)  评论(0编辑  收藏  举报