使用RestSharp保存cookie

abe*_*abe 1 c# rest windows-phone-7 restsharp

我正在尝试使用RestSharp在WinClhone 7 Mango的RestClients和应用程序会话之间保持cookie.

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

小智 5

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

RestSharp 102.4+支持对来自同一IRestClient的所有请求使用共享的System.Net.CookieContainer.通过这样做,响应中设置或未设置的任何cookie将用于后续请求中.要使用共享的CookieContainer,只需在使用它之前在RestClient实例上设置该属性:

var client = new RestClient ("http://server/");
client.CookieContainer = new System.Net.CookieContainer();
Run Code Online (Sandbox Code Playgroud)

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