c# - 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);
解决方案
推荐阅读
- laravel - 由 number_format() 函数格式化后遇到的格式不正确的数值
- ios - 自定义洗牌算法 - Swift
- ios - 如何为 GMSMarker 创建边界
- c++ - 在 C++ 中的启动画面之后显示主窗口 - QT
- android - 带有实时音频流的 Android 背景音频
- amazon-web-services - 将 aws 实例导出到 .VMDK 文件中
- qt - 如何在不使用信号和插槽的情况下使用 qt c++ 中的按钮进入下一页?
- r - 如何在任意经度范围内移动ggplot2地图中的坐标
- php - 如果用户尚未登录,如何显示警报
- angular6 - 在Angular 6反应形式中绑定嵌套的复选框数组时遇到问题