No cache with HttpClient in Windows Phone 8

后端 未结 5 400
夕颜
夕颜 2020-12-03 18:40

I\'ve read that in order to disable caching while using get and post methods in HttpClient, I need to use a WebRequestHandler as my HttpClien

5条回答
  •  猫巷女王i
    2020-12-03 18:58

    I found 3 ways

    1. Add a random Query String to the end of your URI (think Guid.NewGuid()) this will avoid caching on the client as the Query String will be different each time

    string uri = "http://host.com/path?cache=" + Guid.NewGuid().ToString();

    1. Specify no cache in the OutgoingResponse header within your WCF service operation:
    var __request = (HttpWebRequest)WebRequest.Create(url.ToString());
    if (__request.Headers == null)
        __request.Headers = new WebHeaderCollection();
    __request.Headers.Add("Cache-Control", "no-cache");
    
    1. markup your service operation with the AspNetCacheProfile attribute:
    [AspNetCacheProfile("GetContent")]  
    public ResultABC GetContent(string abc)  
    {  
      __request = (HttpWebRequest)WebRequest.Create(abc);
      return __request;  
    }
    

    And update your web.config

      
      
           
            
               
                   
               
          
      
    ...  
    
    

提交回复
热议问题