HttpWebRequest 提交数据的问题

ArmStronger 2015-07-13 03:45:03
我想提交一些数据到一个网站上去(Asp.net),目前登录已经成功,但是post数据没反应。请高手帮忙看看
通过抓包查看需要的参数如下


然后我构造了post的数据如下
StringBuilder postData = new StringBuilder();
postData.Append("IsDBWBLBXS = 1");
postData.Append("&action = add");
postData.Append("&ddl_sBank = 00");
postData.Append("&ddl_sBankName = " + systemMethod.EncodeURL("无"));
postData.Append("&ddl_sGYJGName=");
postData.Append("&ddl_sLBCode=0101");
postData.Append("&ddl_sLBName =" + systemMethod.EncodeURL("一般保障户"));
postData.Append("&ddl_sZPYYCode = 02");
postData.Append("&ddl_sZPYYName = " + systemMethod.EncodeURL("灾害"));
postData.Append("&gID=");
postData.Append("&hidMZ=");
postData.Append("&hidOldYHK=");
postData.Append("&hidRoleType = B");
postData.Append("&hidTX=");
postData.Append("&hidType = 01");
postData.Append("&hidlimit = 0");
postData.Append("&sAreaCodeold=");
postData.Append("&sFamilyYHZHold=");
postData.Append("&txt_dSQRQ = 2015-07-12");
postData.Append("&txt_iJB = B");
postData.Append("&txt_sAdrr =" + systemMethod.EncodeURL("黄平县谷陇镇谷陇村委会"));
postData.Append("&txt_sBZJLQZH =");
postData.Append("&txt_sFamilyYHZH=");
postData.Append("&txt_sHzIdcard = 522622198207081532");
postData.Append("&txt_sHzName =" + systemMethod.EncodeURL("测试张三"));
postData.Append("&txt_sJTLBCode = 01");
postData.Append("&txt_sJTLBName = " + systemMethod.EncodeURL("农村低保"));
postData.Append("&txt_sKHR = " + systemMethod.EncodeURL("测试张三"));
postData.Append("&txt_sSQLY =" + systemMethod.EncodeURL("无"));
postData.Append("&txt_sStructure=");
postData.Append("&txt_sTel=");
postData.Append("&txt_sYZBM=");
postData.Append("&uc_btnSelectArea1$hidAreaCode = 522622103201");
postData.Append("&uc_btnSelectArea1$hidAreaName =" + systemMethod.EncodeURL("谷陇村委会"));


如后用一个封装好的类把数据提交过去,response的状态返回OK,但是没有成功,也没返回需要的数据。

request = httpHelper.GetHttpWebRequest(AddPersonUrl, HttpWebContentType.Form, HttpWebMethod.POST, postData);
//接收响应
response = httpHelper.GetHttpWebResponse(request);


听过要把viewstate和eventValidation一起传过去才能post,我传了也还是一样没反应,麻烦高手给我指点下,哪里有问题,拜托了



...全文
169 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ArmStronger 2015-07-13
  • 打赏
  • 举报
回复
引用 2 楼 starfd 的回复:
=号左右貌似不需要空格
唉,的确是空格的问题,细节问题没注意啊,多谢提醒
ArmStronger 2015-07-13
  • 打赏
  • 举报
回复
引用 2 楼 starfd 的回复:
=号左右貌似不需要空格
我试试看
ArmStronger 2015-07-13
  • 打赏
  • 举报
回复
引用 1 楼 AK_47_A 的回复:
代码贴全一点,是否添加了cookies request.CookieContainer
都设置了的
 public HttpWebRequest GetHttpWebRequest(string Uri, HttpWebContentType contentType, HttpWebMethod httpWebMethod, string postData)
        {
            try
            {
                request = (HttpWebRequest)WebRequest.Create(Uri);
                request.Credentials = CredentialCache.DefaultCredentials;
                request.UserAgent = UserAgent;
                request.Timeout = 10000;
                request.Method = httpWebMethod.ToString();
                if (contentType == HttpWebContentType.Form)
                {
                    request.ContentType = this.FormContent;
                }
                else
                {
                    request.ContentType = this.JsonContent;
                }
                //必须设置CookieContainer存储请求返回的Cookies
                if (CookieContainer != null)
                {
                    request.CookieContainer = CookieContainer;
                }
                else
                {
                    request.CookieContainer = new CookieContainer();
                    CookieContainer = request.CookieContainer;
                }
                request.KeepAlive = true;
                request.AllowAutoRedirect = false;   // 不用需自动跳转
                if (httpWebMethod == HttpWebMethod.POST)
                {
                    if (!string.IsNullOrEmpty(postData))
                    {
                        //提交请求  
                        byte[] postdatabytes = Ecoding.GetBytes(postData);
                        request.ContentLength = postdatabytes.Length;
                        Stream stream = request.GetRequestStream();
                        //设置POST 数据
                        stream.Write(postdatabytes, 0, postdatabytes.Length);
                        stream.Close();
                    }
                }
                return request;
            }
            catch(WebException ex)
            {
                throw ex;
            }
        }

        public HttpWebResponse GetHttpWebResponse(HttpWebRequest request)
        {
            try
            {                
                //接收响应  
                response = (HttpWebResponse)request.GetResponse();
                return response;
            }
            catch (WebException ex)
            {
                throw ex;
            }           
        }
  • 打赏
  • 举报
回复
=号左右貌似不需要空格
亡魂葬爱 2015-07-13
  • 打赏
  • 举报
回复
代码贴全一点,是否添加了cookies request.CookieContainer

110,476

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧