本文整理汇总了C#中System.Net.CookieContainer.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# CookieContainer.ToJson方法的具体用法?C# CookieContainer.ToJson怎么用?C# CookieContainer.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.CookieContainer
的用法示例。
在下文中一共展示了CookieContainer.ToJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyConfiguration
public async Task ApplyConfiguration(JToken configJson)
{
cookies = new CookieContainer();
client = new HttpClient(handler);
var configSaveData = new JObject();
if (OnSaveConfigurationRequested != null)
OnSaveConfigurationRequested(this, configSaveData);
var config = new ConfigurationDataBasicLogin();
config.LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string> {
{ "username", config.Username.Value },
{ "password", @config.Password.Value },
{ "login", "Login" },
{ "keeplogged", "1" }
};
var content = new FormUrlEncodedContent(pairs);
var message = CreateHttpRequest(new Uri(LoginUrl));
message.Content = content;
//message.Headers.Referrer = new Uri(LoginUrl);
string responseContent;
JArray cookieJArray;
if (Program.IsWindows)
{
// If Windows use .net http
var response = await client.SendAsync(message);
responseContent = await response.Content.ReadAsStringAsync();
cookieJArray = cookies.ToJson(SiteLink);
}
else
{
// If UNIX system use curl, probably broken due to missing chromeUseragent record for CURL...cannot test
var response = await CurlHelper.PostAsync(LoginUrl, pairs);
responseContent = Encoding.UTF8.GetString(response.Content);
cookieHeader = response.CookieHeader;
cookieJArray = new JArray(response.CookiesFlat);
}
if (!responseContent.Contains("logout.php?"))
{
CQ dom = responseContent;
dom["#loginform > table"].Remove();
var errorMessage = dom["#loginform"].Text().Trim().Replace("\n\t", " ");
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
}
else
{
configSaveData = new JObject();
configSaveData["cookies"] = cookieJArray;
if (OnSaveConfigurationRequested != null)
OnSaveConfigurationRequested(this, configSaveData);
IsConfigured = true;
}
}