2

我正在尝试使用 RestSharp 在 WinPhone 7 Mango 的 RestClients 和应用程序会话之间获取一个 cookie。

如果我使用单个 RestClient 实例,则 cookie 会持续存在。我希望 cookie 在 RestClient 实例和用户返回应用程序之间持续存在。

4

2 回答 2

7

RestSharp 最近添加了自动 cookie 支持!

RestSharp 102.4+ 支持对来自同一个 IRestClient 的所有请求使用共享的 System.Net.CookieContainer。通过这样做,响应中设置或取消设置的任何 cookie 都将在后续请求中使用。为了使用共享的 CookieContainer,只需在使用前设置 RestClient 实例的属性:

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

文档:https://github.com/restsharp/RestSharp/wiki/Cookies

于 2013-11-20T16:39:50.860 回答
-1

您需要手动保存 cookie 信息,RestSharp 中不支持在会话之间保存 cookie。

于 2012-01-25T16:09:00.760 回答