奇怪的单声道CookieContainer行为

时间:2015-07-20 06:25:25

标签: c# .net mono

以下是代码:

本质上,Logon.Cookies只是一个根据登录页面的响应构建的cookie容器。登录后,其值永远不会改变。

在Windows .NET 4.5上,cookie计数保持为8.

在ubuntu的单声道上,对于此函数调用的每个循环,cookie计数增加2 - 我相信它对导致登录的问题负责。

正在使用多个主机,所以也许这就是原因 - 但同样,Logon.Cookies在登录后永远不会改变。

Uri newUri = new Uri(FinalURL.Replace(HostMain, Hosts[bestHostIndex]));
                var request = (HttpWebRequest)WebRequest.Create(newUri);
                request.Method = "GET";
                request.ServicePoint.ConnectionLimit = 1000;
                request.AllowAutoRedirect = true;
                request.KeepAlive = true;
                request.Referer = EscapedURL;
                request.UserAgent = UA;
                request.Headers.Add("Pragma", "no-cache");
                request.Timeout = 3000;
                request.ReadWriteTimeout = 3000;
                request.Host = HostMain;
                request.Proxy = null;
                request.CookieContainer = Logon.Cookies;
                Console.WriteLine("Container count: {0}\r\nCookies count: {1}", request.CookieContainer.Count, Logon.Cookies.Count);
                using (var resp = request.GetResponse())
                {
                    using (var responseStream = resp.GetResponseStream())
                    {
                        using (var reader = new StreamReader(responseStream))
                        {
                            ret = reader.ReadToEnd();
                        }
                    }

                }

                return ret;

单声道输出示例(忽略#0 0):

3        0       0
Container count: 11
Cookies count: 11
4        0       0
Container count: 13
Cookies count: 13
5        0       0
Container count: 15
Cookies count: 15
6        0       0
Container count: 17
Cookies count: 17
7        0       0
Container count: 19
Cookies count: 19
8        0       0
Container count: 21
Cookies count: 21
c9       0       0
Container count: 23
Cookies count: 23
10       0       0
Container count: 25
Cookies count: 25
11       0       0
Container count: 27
Cookies count: 27
12       0       0
Container count: 29
Cookies count: 29
13       0       0
Container count: 31
Cookies count: 31
c14      0       0
Container count: 33
Cookies count: 33
15       0       0
Container count: 35
Cookies count: 35

编辑:

好的问题是,在网络服务器的响应之后,mono继续将cookie添加到容器中。似乎是一个单声道的错误

0 个答案:

没有答案