Post方式的主要是得到CookieContainer,然后在登陆的时候附加上它就OK了,现在发现对于Get方式的,却无效,老是提示Cannot send a content-body with this verb-type

解决方案 »

  1.   

    HttpWebRequest是支持Get Post方式的
    看看你的参数是不是写错了
      

  2.   

    request.ContentType = "application/x-www-form-urlencoded";
    比如这个Type只能再Post中用
    再Get中去掉这一行
      

  3.   

    应该没问题,你的代码?
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  4.   

    有劳楼上仁兄帮看看        private void Form1_Load(object sender, EventArgs e)
            {
                string url = "http://www.abc.com/loginGr.jsp";
                string username = "105";
                string password = "221";
                Login_job12333(url,username,password,Get_cookiecontainer(url));
            }
            public CookieContainer Get_cookiecontainer(string url)
            {
                CookieContainer c1 = new CookieContainer();
                HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url);
                rq1.CookieContainer = new CookieContainer();
                HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse();
                c1 = rq1.CookieContainer;
                return c1;
            }
            public void Login_job12333(string url, string username, string password, CookieContainer cc)
            {
                HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url);
                rq1.Referer = url;
                rq1.AllowAutoRedirect = true;
                rq1.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
                rq1.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*";
                rq1.Method = "GET";
                rq1.CookieContainer = cc;
                string s03 = "aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password;
                byte[] b1 = Encoding.GetEncoding("GB2312").GetBytes(s03);
                rq1.ContentLength = b1.Length;
                Stream sw1 = rq1.GetRequestStream();
                sw1.Write(b1, 0, b1.Length);
                sw1.Close();
                HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse();            Stream rc1 = rp1.GetResponseStream();
                StreamReader read1 = new StreamReader(rc1, System.Text.Encoding.Default);
                string s1 = read1.ReadToEnd();
                read1.Close();
                rp1.Close();
            }
      

  5.   

    不用设置ContentLength 
    直接用url= "http://www.abc.com/aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password;
      

  6.   

    feiyun0112兄弟提醒得好
    我直接在浏览器中输入http://www.abc.com/aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password可以进入的
    问题是,我            HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url);
                rq1.AllowAutoRedirect = true;
                HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse();
    确提示404错误找不到server
      

  7.   

    谢谢,我给你发csdn短信息了,请查收
      

  8.   

    解决了,谢谢feiyun0112(http://feiyun0112.cnblogs.com/) 老师!!
    直接reques,response不行,还得附加上cookiecontainer!