Restsharp表单身份验证

时间:2012-10-23 19:59:11

标签: cookies forms-authentication restsharp

有可能吗?那怎么样?

var client = new RestClient("http://localhost:58746");
var request = new RestRequest("Users/Login", Method.POST);
request.AddParameter("UserName", "user");
request.AddParameter("Password", "12345");
request.AddParameter("RememberMe", true);
request.AddParameter("ReturnUrl", "http://localhost:58746");

if (response.StatusCode == HttpStatusCode.OK)
{
  var cookie = response.Cookies.FirstOrDefault(x => x.Name == FormsAuthentication.FormsCookieName); // yeah but that will not get the cookie.
}

如何获取该Cookie?

1 个答案:

答案 0 :(得分:1)

我能够以这种方式工作:

var cookie = response.Cookies.FirstOrDefault(x => x.Name == FormsAuthentication.FormsCookieName);