Sunday, 15 July 2012

c# - How I refresh a HttpWebRequest object on Windows Phone -


I am writing a windows phone application where I need to request an http I return this request for me a random value It always changes when I request my URL.

Then I have an app with a button, when I click it I get the random value that I want but, if I click the button again I get the same random value! ! I put a breakpoint on the server and it has just arrived once, if 10 click on the button then it will only reach breakpoint for the first time !! Whenever I button I have a new random value!

Click on I need and I need to use a CookieContainer because on my server I need to keep some items defined in this session. If I use the CookieContainer, I can not keep the session, so when I call the second request I have no objects there.

  Tasks & lt async private; String & gt; RequestURLData (HttpWebRequest request) {HttpWebResponse response = (HttpWebResponse) Task & LT; WebResponse & gt; .Factory.FromAsync (request.BeginGetResponse, request.EndGetResponse, request); Var reactionflow = feedback Gateresonsstream (); Var sr = new streamrider (responses); Receive string = wait sr.ReadToEndAsync (); Retrieve; } Private async works & lt; String & gt; RequestUrl (string URL, cookieContainer cookie) {var request = WebRequest.Create (new URI) as HttpWebRequest; request. Cook Containen = Cookie; Wait for this return. Request URL (request); } Button_Click (Object Sender, RoutedEventArgs E) {CookieContainer Cookie = New CookieContainer () async Personal; Var results = awaiting this .request URL (this.urlBase + "getRandomNum", cookies); Result = Waiting for this. Request url (this.urlBase + "getAnotherValue", cookie); }    

You are running in response caching - add a random string at the end of your The URL that your server ignores is that you do not cache:

  random_rand = new random (); Private async Button_Click (Object Sender, RoutedEventArgs e) {CookieContainer cookie = new CookieContainer (); Var result = Wait for this. Request URL (this.urlBase + "getRandomNum and Rubbish =" + _rand.Next (), Cookies); ...}    

No comments:

Post a Comment