如何使用c#在Web请求中获取cookie?

时间:2017-01-18 20:14:39

标签: c# cookies

我是c#语言的新手。我想编写此代码以将数据发布到网址:

byte[] data = Encoding.ASCII.GetBytes($"Identifier={"anyUsername"}&Password={"Password"}");
            WebRequest request = WebRequest.Create("http://users.tclnet.ir/Authentication/LogOn");
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }
            string responseContent = null;
            using (WebResponse response = request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    using (StreamReader sr99 = new StreamReader(stream))
                    {
                        responseContent = sr99.ReadToEnd();
                    }
                }
            }


但我想从那个答案得到cookie,我怎样才能编写代码来实现它呢?

0 个答案:

没有答案