[C#] HttpWebRequest 存取 WEB API 不要有Cache的寫法

 文章來自 http://jashliao.pixnet.net/blog/post/223322602-c%23-httpwebrequest-%E5%AD%98%E5%8F%96-web-api-%E4%B8%8D%E8%A6%81%E6%9C%89cache%E7%9A%84%E5%AF%AB%E6%B3%95

片段程式碼:

 

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

 

//–
//定義此req的緩存策略
//https://msdn.microsoft.com/zh-tw/library/system.net.webrequest.cachepolicy(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
 

HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);

request.CachePolicy = noCachePolicy;
//–

request.Method = “GET”;//request.Method = “POST”;

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: 來玩C#