当前位置: 首页>>代码示例>>C#>>正文


C# Cache.HttpRequestCachePolicy类代码示例

本文整理汇总了C#中System.Net.Cache.HttpRequestCachePolicy的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestCachePolicy类的具体用法?C# HttpRequestCachePolicy怎么用?C# HttpRequestCachePolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpRequestCachePolicy类属于System.Net.Cache命名空间,在下文中一共展示了HttpRequestCachePolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateRequest

        private static HttpWebRequest CreateRequest(string url, string method)
        {
            int timeout = Convert.ToInt16(ConfigurationManager.AppSettings["timeout"]);
            string userAgent = ConfigurationManager.AppSettings["userAgent"];

            try
            {
                var uri = new Uri(url);
                var request = (HttpWebRequest)WebRequest.Create(uri);
                if (method != "GET")
                {
                    WebRequest.DefaultWebProxy = new WebProxy();
                    request.Timeout = timeout;
                    request.UserAgent = userAgent;
                    var policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
                    HttpWebRequest.DefaultCachePolicy = policy;
                    var noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                    request.CachePolicy = noCachePolicy;
                }
                return request;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
                return null;
            }
        }
开发者ID:Grandman,项目名称:kursach,代码行数:27,代码来源:HttpRequest.cs

示例2: Ctor_ExpectedPropertyValues

 public void Ctor_ExpectedPropertyValues(
     HttpRequestCachePolicy p, HttpRequestCacheLevel level, TimeSpan maxAge, TimeSpan maxStale, TimeSpan minFresh, DateTime cacheSyncDate)
 {
     Assert.Equal(level, p.Level);
     Assert.Equal(maxAge, p.MaxAge);
     Assert.Equal(maxStale, p.MaxStale);
     Assert.Equal(minFresh, p.MinFresh);
     Assert.Equal(cacheSyncDate, p.CacheSyncDate);
     Assert.StartsWith("Level:", p.ToString());
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:10,代码来源:HttpRequestCachePolicyTest.cs

示例3: CreateWebApiRequest

 private HttpWebRequest CreateWebApiRequest(String relativeUri)
 {
     var request = (HttpWebRequest)WebRequest.Create(new Uri(_uri, relativeUri));
     request.ContentType = SchedulerConstants.RequestJsonContentType;
     request.Headers.Add("Authorization",
                         new Signature(this._subscriptionId, this._secretKey).ToString());
     HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
     request.CachePolicy = noCachePolicy;
     return request;
 }
开发者ID:AditiTechnologies,项目名称:Aditi.Scheduler,代码行数:10,代码来源:ScheduledTasks.cs

示例4: Test_WebRequest_03

 public static void Test_WebRequest_03(string url)
 {
     // create HttpWebRequest or FileWebRequest
     WebRequest req = WebRequest.Create(url);
     HttpRequestCachePolicy cachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
     req.CachePolicy = cachePolicy;
     // RequestCachePolicy
     _tr.WriteLine("Test_WebRequest_03");
     _tr.WriteLine("  url : \"{0}\"", url);
     _tr.WriteLine("  WebRequest.Create(url) : \"{0}\"", req);
 }
开发者ID:labeuze,项目名称:source,代码行数:11,代码来源:Test_WebRequest_f.cs

示例5: GetResponse

        public string GetResponse(string host, IDictionary<string, object> arguments,
            bool useCookies = false)
        {
            const string contentType = "application/x-www-form-urlencoded";
            const string requestType = "POST";

            Logging.LogLine("POSTing to " + host + " " + arguments.GetHashCode(), "browser serv");

            var isFirst = true;

            if (useCookies)
            {
                if (!arguments.ContainsKey("csrf_token"))
                    arguments["csrf_token"] = GetCsrfToken();
            }

            var totalRequest = new StringBuilder();
            foreach (var arg in arguments.Where(arg => arg.Key != "type"))
            {
                if (!isFirst)
                    totalRequest.Append('&');
                else
                    isFirst = false;

                totalRequest.Append(arg.Key);
                totalRequest.Append('=');
                totalRequest.Append(HttpUtility.UrlEncode((string) arg.Value));
            }

            var toPost = Encoding.ASCII.GetBytes(totalRequest.ToString());

            var cachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
            var req = (HttpWebRequest) WebRequest.Create(host);
            req.CachePolicy = cachePolicy;
            req.Method = requestType;
            req.ContentType = contentType;
            req.ContentLength = toPost.Length;
            req.UserAgent = Constants.FriendlyName;

            if (useCookies)
                req.CookieContainer = loginCookies;

            using (var postStream = req.GetRequestStream())
                postStream.Write(toPost, 0, toPost.Length);

            using (var rep = (HttpWebResponse) req.GetResponse())
            using (var answerStream = rep.GetResponseStream())
            {
                if (answerStream == null)
                    return null;
                using (var answerReader = new StreamReader(answerStream))
                    return answerReader.ReadToEnd();
            }
        }
开发者ID:ZornTaov,项目名称:slimCat,代码行数:54,代码来源:BrowserService.cs

示例6: GetResponseJSON

 // retornar la respuesta en JSON.
 private static string GetResponseJSON(string uri)
 {
     HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
     HttpWebRequest.DefaultCachePolicy = policy;
     WebRequest request = WebRequest.Create(uri);
     HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
     request.CachePolicy = noCachePolicy;
     WebResponse response = request.GetResponse();
     using (Stream responseStream = response.GetResponseStream())
     {
         StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
         return reader.ReadToEnd();
     }
 }
开发者ID:plazasdesaweb,项目名称:SASP,代码行数:15,代码来源:WSL.cs

示例7: Get

        /// <summary>
        /// Gets web response of request specifying accept header header explicitly
        /// </summary>
        /// <param name="request">HttpWebRequest request</param>
        /// <param name="acceptHeaderValue">The specified accept header</param>
        /// <param name="maximumPayloadSize">Maximum size of response in byte to be allowed to receive</param>
        /// <returns>Web response</returns>
        public static Response Get(HttpWebRequest request, string acceptHeaderValue, int maximumPayloadSize)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (!string.IsNullOrEmpty(acceptHeaderValue))
            {
                request.Accept = acceptHeaderValue;
            }

            // make sure cache disabled, otherwise intermediate proxy would likely return cached responses
            HttpRequestCachePolicy cachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
            request.CachePolicy = cachePolicy;
            return WebHelper.Get(request, maximumPayloadSize);
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:24,代码来源:WebResponseHelper.cs

示例8: GetResponse

        public string GetResponse(string host, IEnumerable<KeyValuePair<string, object>> arguments,
            bool useCookies = false)
        {
            const string contentType = "application/x-www-form-urlencoded";
            const string requestType = "POST";

            var isFirst = true;

            var totalRequest = new StringBuilder();
            foreach (var arg in arguments.Where(arg => arg.Key != "type"))
            {
                if (!isFirst)
                    totalRequest.Append('&');
                else
                    isFirst = false;

                totalRequest.Append(arg.Key);
                totalRequest.Append('=');
                totalRequest.Append(HttpUtility.UrlEncode((string) arg.Value));
            }

            var toPost = Encoding.ASCII.GetBytes(totalRequest.ToString());

            var cachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
            var req = (HttpWebRequest) WebRequest.Create(host);
            req.CachePolicy = cachePolicy;
            req.Method = requestType;
            req.ContentType = contentType;
            req.ContentLength = toPost.Length;

            if (useCookies)
                req.CookieContainer = loginCookies;

            using (var postStream = req.GetRequestStream())
                postStream.Write(toPost, 0, toPost.Length);

            using (var rep = (HttpWebResponse) req.GetResponse())
            using (var answerStream = rep.GetResponseStream())
            {
                if (answerStream == null)
                    return null;
                using (var answerReader = new StreamReader(answerStream))
                    return answerReader.ReadToEnd(); // read our response
            }
        }
开发者ID:Khayde,项目名称:slimCat,代码行数:45,代码来源:Browser.cs

示例9: TestCache

        public void TestCache()
        {
            HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Revalidate);
              Session.CachePolicy = policy;

              Request req = new Request(Session, new Uri("http://www.dr.dk/drfront/images//2013/05/21/c=0,17,1024,505;w=300;42676.jpg"));

              using (var resp = req.Accept("image/jpeg").Get<byte[]>())
              {
            resp.SaveToFile("c:\\tmp\\scrap.jpg");
            Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
              }

              using (var resp = req.Accept("image/jpeg").Get<byte[]>())
              {
            resp.SaveToFile("c:\\tmp\\scrap.jpg");
            Assert.AreEqual(HttpStatusCode.NotModified, resp.StatusCode);
              }
        }
开发者ID:JornWildt,项目名称:Ramone,代码行数:19,代码来源:CachePolicyTests.cs

示例10: GetRequestModel

        /// <summary>
        /// 请求并返回
        /// </summary>
        public static string GetRequestModel()
        {
            var url = string.Format("http://192.168.1.180:8002/login.aspx?key={0}", "test");
            HttpWebRequest webRequest = HttpWebRequest.Create(url) as HttpWebRequest;
            webRequest.Method = "GET";
            HttpRequestCachePolicy cPolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
            webRequest.CachePolicy = cPolicy;
            webRequest.Pipelined = false;
            webRequest.KeepAlive = false;
            webRequest.AllowAutoRedirect = true;
            webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1";
            webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            webRequest.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
            webRequest.Headers.Add("Cookie", "JSESSIONID=396C8439833102EFAF868D6297A9D8FD.web25_8081; __utma=142379556.1006189020.1343613376.1343613376.1343651790.2; __utmb=142379556.2.10.1343651790; __utmc=142379556; __utmz=142379556.1343613376.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)");
            HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse;

            var strRet = string.Empty;
            try
            {
                System.IO.Stream resStream = response.GetResponseStream();
                Encoding encode = System.Text.Encoding.Default;
                StreamReader readStream = new StreamReader(resStream, encode);
                Char[] read = new Char[256];
                int count = readStream.Read(read, 0, 256);
                while (count > 0)
                {
                    String str = new String(read, 0, count);
                    strRet = strRet + str;
                    count = readStream.Read(read, 0, 256);
                }
                resStream.Close();
            }
            catch (Exception e)
            {
                strRet = "";
            }
            return strRet;
        }
开发者ID:zhipuchen,项目名称:Storage,代码行数:41,代码来源:HttpRequestRespone.cs

示例11: RequestCachingSectionInternal

 internal RequestCachingSectionInternal(RequestCachingSection section)
 {
     if (!section.DisableAllCaching)
     {
         this.defaultCachePolicy = new RequestCachePolicy(section.DefaultPolicyLevel);
         this.isPrivateCache = section.IsPrivateCache;
         this.unspecifiedMaximumAge = section.UnspecifiedMaximumAge;
     }
     else
     {
         this.disableAllCaching = true;
     }
     this.httpRequestCacheValidator = new HttpRequestCacheValidator(false, this.UnspecifiedMaximumAge);
     this.ftpRequestCacheValidator = new FtpRequestCacheValidator(false, this.UnspecifiedMaximumAge);
     this.defaultCache = new WinInetCache(this.IsPrivateCache, true, true);
     if (!section.DisableAllCaching)
     {
         HttpCachePolicyElement defaultHttpCachePolicy = section.DefaultHttpCachePolicy;
         if (defaultHttpCachePolicy.WasReadFromConfig)
         {
             if (defaultHttpCachePolicy.PolicyLevel == HttpRequestCacheLevel.Default)
             {
                 HttpCacheAgeControl cacheAgeControl = (defaultHttpCachePolicy.MinimumFresh != TimeSpan.MinValue) ? HttpCacheAgeControl.MaxAgeAndMinFresh : HttpCacheAgeControl.MaxAgeAndMaxStale;
                 this.defaultHttpCachePolicy = new HttpRequestCachePolicy(cacheAgeControl, defaultHttpCachePolicy.MaximumAge, (defaultHttpCachePolicy.MinimumFresh != TimeSpan.MinValue) ? defaultHttpCachePolicy.MinimumFresh : defaultHttpCachePolicy.MaximumStale);
             }
             else
             {
                 this.defaultHttpCachePolicy = new HttpRequestCachePolicy(defaultHttpCachePolicy.PolicyLevel);
             }
         }
         FtpCachePolicyElement defaultFtpCachePolicy = section.DefaultFtpCachePolicy;
         if (defaultFtpCachePolicy.WasReadFromConfig)
         {
             this.defaultFtpCachePolicy = new RequestCachePolicy(defaultFtpCachePolicy.PolicyLevel);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:RequestCachingSectionInternal.cs

示例12: GetHTML

        public WebReqResult GetHTML(string url)
        {
            WebReqResult result = new WebReqResult();

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                HttpRequestCachePolicy cachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                WebHeaderCollection requestHeaderCollection = request.Headers;

                requestHeaderCollection.Add("Accept-Language:en-US,en;q=0.5");

                request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                request.CachePolicy = cachePolicy;
                request.Proxy = null; // Proxy autodetection slows down requests ( http://stackoverflow.com/a/935728 )
                request.Timeout = 5000;
                request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0";

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    Stream stream = response.GetResponseStream();
                    StreamReader readStream = new StreamReader(stream);
                    string html = WebUtility.HtmlDecode(readStream.ReadToEnd());
                    result.Success = true;
                    result.HTML = html;
                }
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Error = e.Message;
            }

            return result;
        }
开发者ID:jlq,项目名称:PageMonitor,代码行数:36,代码来源:WebReq.cs

示例13: CreateRequest

        private static HttpWebRequest CreateRequest(Uri url, string data, string method, string contentType, NameValueCollection headers, int timeout, bool gzip, NetworkCredential credential = null)
        {
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = method.ToUpper();
            request.ContentType = contentType;
            var noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
            request.CachePolicy = noCachePolicy;
            request.Timeout = timeout;
            request.Credentials = credential;

            if (headers != null)
                request.Headers.Add(headers);

            if (gzip)
                request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");

            if (data != null)
            {
                var encoding = new UTF8Encoding();
                var byteData = encoding.GetBytes(data);
                request.ContentLength = byteData.Length;

                using (var postStream = request.GetRequestStream())
                {
                    postStream.Write(byteData, 0, byteData.Length);
                }
            }
            else if (request.Method != "GET")
            {
                //Specify a zero content length to prevent 411s
                request.ContentLength = 0;
            }

            return request;
        }
开发者ID:davidwinchurch,项目名称:DW.JSON.TypedDeserialization,代码行数:36,代码来源:RestHelper.cs

示例14: SetCacheControlWithMaxAgeAndMinFresh

 public void SetCacheControlWithMaxAgeAndMinFresh(TimeSpan maxAge, TimeSpan minFresh)
 {
     _cachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAgeAndMinFresh, maxAge, minFresh);
 }
开发者ID:heciqi,项目名称:EasyHttp,代码行数:4,代码来源:HttpRequest.cs

示例15: SetCacheControlWithMaxAgeAndMaxStale

 public void SetCacheControlWithMaxAgeAndMaxStale(TimeSpan maxAge, TimeSpan maxStale)
 {
     _cachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAgeAndMaxStale, maxAge, maxStale);
 }
开发者ID:heciqi,项目名称:EasyHttp,代码行数:4,代码来源:HttpRequest.cs


注:本文中的System.Net.Cache.HttpRequestCachePolicy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。