如何从网站获取所有cookie而不是少数。 [英] How do I get ALL cookies from a website instead of only a few.

查看:104
本文介绍了如何从网站获取所有cookie而不是少数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提出了在网站上获取所有Cookie的申请,但我注意到该应用只输出了一些。为什么会发生这种情况并且可以解决?



我尝试了什么:



I made a application for getting all cookies on a website but I noticed the app only outputs a few. Why is this happening and is this fixable?

What I have tried:

try
{

string url = textBox1.Text;
               
HttpWebRequest myCall = (HttpWebRequest)WebRequest.Create(url); 

myCall.CookieContainer = new CookieContainer();

response = (HttpWebResponse)myCall.GetResponse();

myCall.AllowAutoRedirect = true;

foreach (Cookie cookie in response.Cookies)
{                   
    listBox1.Items.Add(cookie.Name);
     listBox1.Items.Add(cookie.Value);
}

myCall.Abort();

}
catch(Exception ex)
{
 MessageBox.Show(ex.Message);
}

推荐答案

你不能。

出于安全考虑,你无法全部获得所有cookie仅与您的会话/域相关的那些...
You can't.
For security reasons you can not get all cookies only those related to your session/domain...


Cookie存储在客户端而不是服务器上,因此您无法从请求到Web服务器获取所有cookie。您的代码正在检查响应,因此您只能看到该响应中正在设置*的cookie,并且网站不会每次都设置所有cookie。例如,当您添加到购物篮时,如果您的cookie中没有购物篮ID,则该网站将添加购物篮ID,您将在添加到购物篮页面的结果中看到该cookie。但是从那时起,您将看不到设置cookie,因为它仅在创建篮子时设置。从那时起,客户必须管理该cookie。
Cookies are stored on the client, not the server so you can't get all cookies from a request to the web server. Your code is examining the response so you'll only see the cookies that are being *set* on that response, and a web site doesn't set all cookies every time. For example when you add to basket if you have no basket id in your cookie the site will add a basket id cookie and you'll see that cookie in the result of the add to basket page. However from then on you won't see that cookie being set as it is only set when the basket is created. From then on it is the client who has to manage that cookie.


这篇关于如何从网站获取所有cookie而不是少数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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