سؤال

I am trying to get a cookie to persist between RestClients and app sessions for WinPhone 7 Mango using RestSharp.

If I use a single RestClient instance the cookie persists. I want the cookie to last between RestClient instances and when a user returns to the app.

هل كانت مفيدة؟

المحلول

RestSharp have recently added automatic cookie support!

RestSharp 102.4+ supports using a shared System.Net.CookieContainer for all requests from the same IRestClient. By doing so, any cookies set or unset in responses will be used in subsequent requests. In order to use a shared CookieContainer, simply set the property on your RestClient instance before using it:

var client = new RestClient ("http://server/");
client.CookieContainer = new System.Net.CookieContainer();

Documentation: https://github.com/restsharp/RestSharp/wiki/Cookies

نصائح أخرى

You need to manually save the cookie info there is no native support in RestSharp for saving your cookie between sessions.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top