当前位置:编程学习 > C#/ASP.NET >>

模拟登陆 POST数据拼接问题

在fireFox上捕获到的POST请求


后台
 string huDongPostData = "fid=" + hs.FID + "\r\n" + "userid=" + student.UserId + "\r\n" + "title=" + hs.Title + "\r\n"
                                    + "require=" + purpose.Require + "\r\n" + "purpose=" + purpose.Purpose + "\r\n" + "contents= " + "\r\n"
                                    + "school=" + student.SchoolID + "\r\n" + "grade=" + student.Grade + "\r\n" + "classroom=" + student.ClassRoom + "\r\n"
                                    + "testwanser=0|0|0" + "\r\n" + "testinfo=已掌握技能" + "\r\n"
                                    + "SiteName= { HuDongFS: '其他方式' , name: '', address: '看书', Time: '',IsJoin:'1' }" + "\r\n" + "SiteAddrees= " + "\r\n"
                                    + "WatchTime=";
其中红色部分的拼接有错吗?

我照这样发送POST请求,服务器返回true(跟我在网页中操作返回的值一样),但是post以后 登陆页面查看居然没操作成功,求大神帮忙!
我的QQ:35914052或者留下大神的QQ,我加你! --------------------编程问答-------------------- 大神 来看看 --------------------编程问答--------------------  public string PostData(string url, string data)
        {
            string respHtml = "";
            UTF8Encoding coding = new UTF8Encoding();
            byte[] postData = coding.GetBytes(data);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)";
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.Timeout = 4000;
            request.KeepAlive = true;
            request.ContentLength = postData.Length;
            request.CookieContainer = loginCookie;

            Stream newStream = request.GetRequestStream();

            //发送数据
            newStream.Write(postData, 0, postData.Length);
            newStream.Close();


            //接收返回值
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                foreach (Cookie cookie in response.Cookies)
                {
                    loginCookie.Add(cookie);
                }
                Stream myStream = response.GetResponseStream();
                StreamReader myReader = new StreamReader(myStream, Encoding.GetEncoding("utf-8"));
                respHtml = myReader.ReadToEnd();

                response.Close();
                myStream.Close();

                response = null;
                myStream = null;
                myReader = null;

                return respHtml;
            }
            catch (Exception ex)
            {
                return respHtml = ex.ToString();
            }
        }

这是我POST请求的方法 --------------------编程问答-------------------- 貌似里面有‘’这样的字符导致的 --------------------编程问答-------------------- 不管小偷
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,