c# HttpClient禁止缓存

using (var client = new HttpClient())
            {

               //方法1:

                CacheControlHeaderValue cacheControl = new CacheControlHeaderValue();
                cacheControl.NoCache = true;
                cacheControl.NoStore = true;
                client.DefaultRequestHeaders.CacheControl = cacheControl;

               //方法2:

                //client.DefaultRequestHeaders.Add("Cache-Control", "no-cache");
                try
                {
                    client.GetStringAsync(url);
                    return true;
                }
                catch
                {
                    return false;
                }
            }

posted @ 2016-10-11 14:10  94cool  阅读(2478)  评论(0编辑  收藏  举报