首页 > 解决方案 > how do save cookies with restclient

问题描述

I want to save the cookies after login, which is convenient for future RestRequest.

settings are not in effect

client.CookieContainer = new CookieContainer ();

this is code:

var _client = new RestClient("https://rocket-league.com");
_client.CookieContainer = new CookieContainer ();
var _request = new RestRequest(Method.GET);

_request.AddCookie("acceptedPrivacyPolicy", "2.0");
var _response = _client.Execute(_request);

// get csrf_token
// eg:<input type='hidden' name='csrf_token' value='2ea76eaca322e809c14ba608425f00f4' />
Regex _token = new Regex("<input type='hidden' name='csrf_token' value='(.*?)' />", RegexOptions.IgnoreCase);
Match match_token = _token.Match(_response.Content);
var csrf_token = "";

if (match_token.Success)
{
    csrf_token = match_token.Groups[1].Value;
}

var client = new RestClient("https://rocket-league.com/functions/login.php");
var request = new RestRequest(Method.POST);

// **** get cookies *****
// ??????  who to do with here?????
request.AddCookie("acceptedPrivacyPolicy", "2.0");

// 5. adds to POST or URL querystring based on Method
request.AddParameter("email", email);
request.AddParameter("password", password);
request.AddParameter("submit", "Go");
request.AddParameter("rememberme", "on");
request.AddParameter("csrf_token", csrf_token);

IRestResponse response = client.Execute(request);

标签: c#cookiesrest-client

解决方案


推荐阅读