在Windows窗体中读取Cookie时出现问题 [英] Problem Reading Cookie in Windows form

查看:206
本文介绍了在Windows窗体中读取Cookie时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,
我有Windows应用程序,我想在浏览器中读取Cookie设置,同时也附有问题的代码.

什么? 我正在做我正在创建Windows用户控件并将其放置在ASP.Net中 从客户端计算机读取cookie值的应用程序.但是 ASP.Net应用程序中的用户控件显示无法读取Cookie 价值.我还附加了我在用户控件中使用的代码,

textBox1.Text ="Hello";
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create("http://127.0.0.1'');




//如果具有
注释,则取消注释以下语句来设置代理,//request.Proxy = new System.Net.WebProxy( http://yourproxyservername:portnumber'');
//request.Proxy.Credentials = CredentialCache.DefaultCredentials;

////定义一个空的CookieContainer类对象

请求.CookieContainer = new CookieContainer();


HttpWebResponse response =(HttpWebResponse)request.GetResponse();原始
HttpWebRequest对象中的//CookieContainer对象
响应.Cookies =请求t.CookieContainer.GetCookies(request.RequestUri); foreach(Cookie cky作为响应.Cookies)
{{ =" + cky.Value);
MessageBox.Show(cky.Name +"=" + cky.Value);
}

Hi,
 I have Windows Application in which i want to read cookie set in the browser i am also attaching my code with question.

What i am doing I am creating Windows user control which i  place in ASP.Net application which read a cookie value from the client machine. But The User Control Display in the ASP.Net application can't read the cookie value. I am also attaching code which i am using in User Control ,

 textBox1.Text = "Hello";
           
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1");
           
           

            //Uncomment the following statements to set up proxy, if have
            //request.Proxy = new System.Net.WebProxy("http://yourproxyservername: portnumber");
            //request.Proxy.Credentials = CredentialCache.DefaultCredentials;

            //Define an empty CookieContainer class object
            //before the HTTP request is sent
            request.CookieContainer = new CookieContainer();


            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            //Assign the Cookie property of the HttpWebResponse object to the original
            //CookieContainer object in the HttpWebRequest object
            response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
            foreach (Cookie cky in response.Cookies)
            {
                Console.WriteLine(cky.Name + " = " + cky.Value);
                MessageBox.Show(cky.Name + " = " + cky.Value);
            }

推荐答案

您正在创建您自己的Cookie容器.尝试通过脚本将document.cookie传递给用户控件.
You are creating your own cookie container. Try pass document.cookie to your user control via script.


这篇关于在Windows窗体中读取Cookie时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆