我用 foreach (Cookie cook in webResponse.Cookies)
{
Console.WriteLine("Cookie:");
Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
Console.WriteLine("Domain: {0}", cook.Domain);
Console.WriteLine("Path: {0}", cook.Path);
Console.WriteLine("Port: {0}", cook.Port);
Console.WriteLine("Secure: {0}", cook.Secure); Console.WriteLine("When issued: {0}", cook.TimeStamp);
Console.WriteLine("Expires: {0} (expired? {1})",
cook.Expires, cook.Expired);
Console.WriteLine("Don't save: {0}", cook.Discard);
Console.WriteLine("Comment: {0}", cook.Comment);
Console.WriteLine("Uri for comments: {0}", cook.CommentUri);
Console.WriteLine("Version: RFC {0}", cook.Version == 1 ? "2109" : "2965"); // Show the string representation of the cookie.
Console.WriteLine("String: {0}", cook.ToString());
}
读取cookie信息,却什么也没有,显示webResponse.Cookies为0.我用 for (int aa = 0; aa < webResponse.Headers.Count ; aa++)
{
Console.WriteLine(webResponse.Headers.GetKey(aa) + " : " + webResponse.Headers.Get(aa));
}读取头文件结果为Pragma : no-cache
Transfer-Encoding : chunked
Cache-Control : no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type : text/html
Date : Sun, 25 May 2008 06:10:58 GMT
Expires : Thu, 19 Nov 1981 08:52:00 GMT
Set-Cookie : PHPSESSID=ca503bf9880b4dd72db87ea7694c9e69; path=/
Server : Apache/2.2.4 (Win32) PHP/5.2.1
X-Powered-By : PHP/5.2.1那么请问这里的Set-Cookie是什么?如何知道这个ID什么时候有效?什么时候过期呢? 谢谢!
{
Console.WriteLine("Cookie:");
Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
Console.WriteLine("Domain: {0}", cook.Domain);
Console.WriteLine("Path: {0}", cook.Path);
Console.WriteLine("Port: {0}", cook.Port);
Console.WriteLine("Secure: {0}", cook.Secure); Console.WriteLine("When issued: {0}", cook.TimeStamp);
Console.WriteLine("Expires: {0} (expired? {1})",
cook.Expires, cook.Expired);
Console.WriteLine("Don't save: {0}", cook.Discard);
Console.WriteLine("Comment: {0}", cook.Comment);
Console.WriteLine("Uri for comments: {0}", cook.CommentUri);
Console.WriteLine("Version: RFC {0}", cook.Version == 1 ? "2109" : "2965"); // Show the string representation of the cookie.
Console.WriteLine("String: {0}", cook.ToString());
}
读取cookie信息,却什么也没有,显示webResponse.Cookies为0.我用 for (int aa = 0; aa < webResponse.Headers.Count ; aa++)
{
Console.WriteLine(webResponse.Headers.GetKey(aa) + " : " + webResponse.Headers.Get(aa));
}读取头文件结果为Pragma : no-cache
Transfer-Encoding : chunked
Cache-Control : no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type : text/html
Date : Sun, 25 May 2008 06:10:58 GMT
Expires : Thu, 19 Nov 1981 08:52:00 GMT
Set-Cookie : PHPSESSID=ca503bf9880b4dd72db87ea7694c9e69; path=/
Server : Apache/2.2.4 (Win32) PHP/5.2.1
X-Powered-By : PHP/5.2.1那么请问这里的Set-Cookie是什么?如何知道这个ID什么时候有效?什么时候过期呢? 谢谢!
解决方案 »
- Hook API 怎么实现webBrowser中的网页中的Flash静音
- 桌面应用程序像QQ 360 那样安装后可以在外网使用是如何实现的?
- 如何使另一个程序的窗体最大化或得到焦点
- WinForm的最小化问题
- 如何这样分配多线程呢?
- 求救:程序写完了,给客户安装时遇到的问题
- 请问如何用C#求矩阵特征值?mm谢谢了!
- 这个语句怎么写
- 如何让判定只能输入英文字母和数字?
- 请问C#,用来开发什么比较好,C#开发的系统,在客户机上运行需要什么环境吗?比如.Net架构等等 ,谢谢
- c#中while(true)是什么意思(菜鸟提问)
- DevExpress控件GridControl 中使用repositoryItemCheckEdit
HttpWebResponse webResponse;
Stream stream;
byte[] byteRequest = System.Text.Encoding.Default.GetBytes(s); //s为我要向服务器提交的数据 httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.xxx.com/yyy/zzz/"); //加载URL
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = byteRequest.Length; stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length); //POST信息
stream.Close(); webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
我向服务器提交了一个数据,模拟点击登陆按钮.
然后读取服务器转向的登陆页面及其他消息.我要分析服务器给我的cookie及所有信息,但是为什么没有cookie呢?
Set-Cookie : PHPSESSID=ca503bf9880b4dd72db87ea7694c9e69; path=/服务器返回 Set-Cookie就是让你在cookieContainer里面增加这样一个cookie.
记住, cookie不是在服务器端保存的
一般情况下,服务器回写的COOKIE是应该在httpwebresponse里的Cookies里得到
但是有情况只在httpwebresponse.header里,而httpwebresponse.Cookies没有,cookieContainer也没有
我猜是不是Cache-Control : no-store的原因不知道有谁能清楚点