I've made short program with 6 textbox that I manually fill in with cookies. Now I want my program to act on specific url as if its logged in.

How can I get that ? I tried this and I get http response that I'm not logged in.

            string url = "myurl string";
            Uri target = new Uri(url);
            CookieContainer gaCookies = new CookieContainer();
            gaCookies.Add(new Cookie("__utma", textBox1.Text) { Domain= target.Host});
            gaCookies.Add(new Cookie("__utmb", textBox2.Text) { Domain = target.Host });
            gaCookies.Add(new Cookie("__utmc", textBox3.Text) { Domain = target.Host });
            gaCookies.Add(new Cookie("__utmz", textBox4.Text) { Domain = target.Host });
            gaCookies.Add(new Cookie("cookiename1", textBox5.Text) { Domain = target.Host });
            gaCookies.Add(new Cookie("cookiename2", textBox6.Text) { Domain = target.Host });
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
            Stream receiveStream = response.GetResponseStream();
            StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
            textBox7.Text = readStream.ReadToEnd();
有帮助吗?

解决方案

You need to set the cookie container of the HTTP request. Add the following line after you create the HtppWebRequest.

myReq.CookieContainer = gaCookies
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top