从http请求访问cookie

时间:2019-06-10 14:13:13

标签: c# cookies httpwebrequest

我试图从C#winform应用程序访问由我们的Web应用程序保存的cookie。我可以从chrome开发人员工具中看到保存的cookie,但是在我的winform应用程序中,cookie容器始终返回0个cookie。不知道我做错了什么。

非常感谢您的帮助和投入!

这是保存cookie的Web应用程序 enter image description here

这是尝试读取cookie的代码,它始终返回0个cookie。 enter image description here

static void Main()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost");
            request.CookieContainer = new CookieContainer();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            foreach (Cookie cky in response.Cookies)
            {
                Console.WriteLine(cky.Name + " = " + cky.Value);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new PrintJobQueue());
        }

这是Fiddler的请求/响应 enter image description here

这是Chrome设置视图中的cookie: enter image description here

0 个答案:

没有答案
相关问题