如何在WebClient中初始化cookie

时间:2016-12-09 14:52:24

标签: c# cookies webclient

this问题的最多投票答案中,有这一行:

cookieJar.Add(new Cookie("my_cookie", "cookie_value", "/", "mysite"));

在这一行中,有“my_cookie”,cookie_value和“mysite”字段。我不知道如何填补这些线。你能告诉我如何填写一个例子吗?提前谢谢。

2 个答案:

答案 0 :(得分:3)

希望这有助于

class Login:
    def __init__(self, user, password):
        self.user = user
        self.password = password


login_details = Login(user='a', password='b')

print(login_details.user)
>> 'a'
print(login_details.password)
>> 'b'

或抬头here了解更多信息

答案 1 :(得分:0)

试试这个:

HttpCookie _cookie = new HttpCookie("Department"); // Create and give name
_cookie.Expires = DateTime.Now.AddDays(30);       // expries in one month
_cookie.Value = "Dep1";                          // set value
HttpContext.Response.Cookies.Add(_cookie);      // add cookie to the context