我用HttpWebRequest 模拟登录后,要用Post的方法去查询数据 ,但是Post后,就会跳转到登录页面,如果不用Post,用Get就可以获取只能获取查询页面  HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
                request.Timeout = 600000 * Settings.Instance.TimeOut;
                request.ReadWriteTimeout = 600000 * Settings.Instance.TimeOut;
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2)";
                request.ContentType = ContentType;
                request.Accept = Accept;
                request.Credentials = CredentialCache.DefaultCredentials;
                request.Method = isPost ? "POST" : "GET";
                if (isPost)
                {
                    if (!string.IsNullOrEmpty(postData))
                    {
                        ASCIIEncoding encoding = new ASCIIEncoding();
                        byte[] data = encoding.GetBytes(postData);
                        request.ContentLength = data.Length;
                        using (Stream stream = request.GetRequestStream())
                        {
                            stream.Write(data, 0, data.Length);
                        }
                    }
                }
                request.CookieContainer = cc;
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default))
                    {
                        return reader.ReadToEnd();
                    }
                }

解决方案 »

  1.   

    自己搞定了

      request.CookieContainer = cc;放到这里 request.Method = isPost ? "POST" : "GET"; 
                    request.CookieContainer = cc;
                    if (isPost)
                    {
                        if (!string.IsNullOrEmpty(postData))
                        {
                            ASCIIEncoding encoding = new ASCIIEncoding();
                            byte[] data = encoding.GetBytes(postData);
                            request.ContentLength = data.Length;
                            using (Stream stream = request.GetRequestStream())
                            {
                                stream.Write(data, 0, data.Length);
                            }
                        }
                    }               
      

  2.   

    就是啊,保存可Cookie才行啦~~
      

  3.   

    不论Post 还是 Get 都需要,有的虽然是Get请求,但是需要你登陆信息的~~所以CookieContainer 加上去