C# 小弟我用HttpWebRequest获得JSESSIONID一直一样,多用户不能同时查询

C# 我用HttpWebRequest获得JSESSIONID一直一样,多用户不能同时查询
本帖最后由 qiaowei361 于 2014-08-26 23:09:52 编辑
我写了一个模拟登录XX网站的程序,我在自己的网站上供用户登录,在从我的服务器去模拟登录XX网站,再返回给用户。
我现在所遇到问题是A用户登录后,B用户随后登录,A用户所得到的数据都是B用户的,如果C用户再登录,A和B用户看到的数据都是C的。反正是被覆盖的。不能同时查询对应自己的数据。

我想要用户各自查询自己的信息,我尝试过Session\cookie\URL参数都是不行阿。

请牛人解决此问题。

以下是代码:


private string GetWeb(string url, string method, string data)
    {
        try
        {

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.KeepAlive = true;
            req.Method = method.ToUpper();
            req.AllowAutoRedirect = true;
            req.CookieContainer = CookieContainers;
            req.ContentType = "application/x-www-form-urlencoded";
            req.UserAgent = IE7;
            req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            req.Timeout = 50000;
            if (Request.QueryString["g"] !=null)
            {
                sburl = Request.QueryString["g"].ToString();
                req.Headers.Add("Cookie: " + sburl);

            }
            if (sburl=="")
            {
                //JSESSIONID=BvLRT80KcnKhgwvG0PyPCf512hpZnf1RJpTQG23XHQN9PPRxh6G1!650146923
                sburl =req.CookieContainer.GetCookieHeader(req.RequestUri);
                sburl = sburl.Replace("JSESSIONID=", "");
            }
            if (method.ToUpper() == "POST" && data != null)
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] postBytes = encoding.GetBytes(data); ;
                req.ContentLength = postBytes.Length;
                Stream st = req.GetRequestStream();
                st.Write(postBytes, 0, postBytes.Length);
                st.Close();
            }

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            Stream resst = res.GetResponseStream();
            StreamReader sr = new StreamReader(resst, Encoding.Default);
            string str = sr.ReadToEnd();

            return str;
        }
        catch (Exception)
        {
            return string.Empty;
        }



所获得的SESSIONID一直一样。我在本地测试,重新运行才会变动 
------解决思路----------------------
你的代码里也没用SESSION啊
------解决思路----------------------
问题问的不清楚,所谓的用户登录是指登录你的网站还是指你内部登录XX网站获得的JSESSIONID
------解决思路----------------------
CookieContainers 应该按用户隔离开
------解决思路----------------------
引用:
Quote: 引用:

CookieContainers 应该按用户隔离开
CookieContainers 应该按用户隔离开,不是的。