Friday 15 February 2013

c# - Access website by using cookie from httpwebrequest windows phone -


After

I have no experience in cookies and I used to use cookies (that I httpwebrequest Trying to get Post method) to reach a website. In the POST method, I made a part of the certification and in the end I got the cookies. How do I use this website to donate a website and it's similar to this?

Hope anyone can give me some advice, pointer or some example code. Thank you for taking

Here's my code so far I have done

  private void GetResponseCallback (IAsyncResult asynchronousResult) {HttpWebRequest request = (HttpWebRequest) asynchronousResult.AsyncState .. // operation HttpWebResponse response = (HttpWebResponse) request.EndGetResponse (asynchronousResult) end; Stream Stream Response = Response Gateresonsstream (); Stream reader stream read = new stream reader (stream response); ((Sprinteweave SW = new streamer (ISIS)) (separate storage file isf = IsolatedStorageFile.GetUserStoreForApplication ()) {(IsolatedStorageFileStream isfs = isf.OpenFile ("CookieExCookies", FileMode.OpenOrCreate, FileAccess.Write)) {foreach (Cookie cookie response value. cookies) {sw.WriteLine (cookieValue.ToString ());} Sw.Close ();}}} // stream object Close stream. Close (); streamRead.Close ( ); response.Close (); //allDone.Set ();}   

Cookie store in the text box

  private void ReadFromIsolatedStorage (() Using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserSto reForApplication ()) {using (IsolatedStorageFileStream isfs = isf .OpenFile ( "CookieExCookies", FileMode.OpenOrCreate)) using {(StreamReader sr = new StreamReader (isfs)) {tbTesting.Text = sr.ReadToEnd (); sr. Close ();}}}}    

You receive and set CookieContainer class can use cookies When you use it, it handles everything for you. You do not need to manually set cookies manually, check the code below.

Make an example of the first CookieContainer class.

  Cookie Container Cookie Container = New Cookie Container ();   

Then use it for authentication and assign then to each use for verification to get cookies HttpWebRequest request = (

  // Request Request for Login HttpWebRequest) WebRequest.Create ("http://mydomain.com/login.svc"); Req.method = "POST"; If (req.SupportsCookieContainer) req.CookieContainer = cookieContainer; .. need a cookie HttpWebRequest REQ = (HttpWebRequest) WebRequest.Create ( "http://mydomain.com/getuserdata.svc") for the rest of your code .. // any other request; Req.method = "POST"; If (req.SupportsCookieContainer) req.CookieContainer = cookieContainer; .. Your other code ..    

No comments:

Post a Comment