Httpwebrequest caching in windows phone 7

2019-04-01 02:08发布

I have an issue with caching while developing an app using wp7. 1 and the httpwebrequest method.

HttpWebRequest request = HttpWebRequest. CreateHttp (s);
request. BeginGetResponse (new AsyncCallback (HandleResponse), request);

The result of the request is the same even in case of a different request content. And in the case of different parameters in the request. How can i fix this issue?

Thanks.

2条回答
相关推荐>>
2楼-- · 2019-04-01 02:44

Usually I get around this adding a unique request identifier to the Uri

This won't work for all instances (as your Uri may already include query strings), but as an example

string s = uri + "?guid=" + Guid.NewGUID();
HttpWebRequest request = HttpWebRequest.CreateHttp(new Uri(s, UriKind.Absolute));
request. BeginGetResponse (new AsyncCallback (HandleResponse), request);
查看更多
女痞
3楼-- · 2019-04-01 02:56

May this helps you. try it

 HttpWebRequest request = HttpWebRequest. CreateHttp (s);
    request.Headers[HttpRequestHeader.CacheControl] = "no-cache"; 
    request.Headers[HttpRequestHeader.Pragma] = "no-cache"; 
    request.Headers[HttpRequestHeader.IfModifiedSince] = dateTime.Now.ToString();
    request. BeginGetResponse (new AsyncCallback (HandleResponse), request);

/*request.Headers[HttpRequestHeader.IfModifiedSince] = dateTime.Now.ToString(); this forces your request to always be performed - this made the trick for me.*/
查看更多
登录 后发表回答