当前位置: 代码迷 >> ASP.NET >> HttpWebRequest post参数有关问题
  详细解决方案

HttpWebRequest post参数有关问题

热度:1876   发布时间:2013-02-25 00:00:00.0
HttpWebRequest post参数问题
我用HttpWebRequest请求链接,post参数过不去,帮忙看下问题所在。
C# code
       HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);            req.KeepAlive = false;            req.Method = "POST";            req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";            req.Credentials = CredentialCache.DefaultCredentials;            req.ContentType = "application/x-form-www-urlencoded";            Encoding encode = new UTF8Encoding();            byte[] b = encode.GetBytes(string.Format("Content={0}&Type={1}&StartDate={2}&EndDate={3}", content, columnname.ToLower() == "macaddress" ? 1 : 0, DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd 00:00:00"), DateTime.Now.Date.ToString("yyyy-MM-dd 00:00:00")));            req.ContentLength = b.Length;            using (Stream stream = req.GetRequestStream())            {                stream.Write(b, 0, b.Length);            }            WebResponse res = req.GetResponse();            StreamReader sr = new StreamReader(res.GetResponseStream(), encode);            string result = sr.ReadToEnd();            res.Close();            sr.Close();

其中content参数是用英文逗号分隔的mac地址,如:14:5A:05:56:F5:A8,0C:74:C2:8B:F8:AA,CC:08:E0:8C:16:BC,0C:77:1A:6E:66:FE,长度是1500个mac逗号分隔。
我看资料,很多都是给GetRequestStream() write参数的,我这样参数没post过去.第三方联调过,却是是没传过去参数。
在线等解答,谢谢


------解决方案--------------------------------------------------------
content 加上 HttpUtility.UrlEncode()
------解决方案--------------------------------------------------------
编一下码,接收方解码
------解决方案--------------------------------------------------------
接收方Server.UrlDecode()一下
  相关解决方案