日期:2014-05-17  浏览次数:20948 次

C#请求网页怎么实现No-Cache方式?
C++这么写的,那C#呢
HINTERNET hHttp = InternetOpenUrl(hSession, url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);

C#怎样no-cache?
 req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
  res = (System.Net.HttpWebResponse)req.GetResponse();

------解决方案--------------------
C# code

public static WebResponse GetResponseNoCache(Uri uri)
{
        // Set a default policy level for the "http:" and "https" schemes.
        HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
        HttpWebRequest.DefaultCachePolicy = policy;
        // Create the request.
        WebRequest request = WebRequest.Create(uri);
        // Define a cache policy for this request only. 
        HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
        request.CachePolicy = noCachePolicy;
        WebResponse response = request.GetResponse();
        Console.WriteLine("IsFromCache? {0}", response.IsFromCache);            
        return response;
}