今天在项目组用json传输数据 post方法提交 发现传输过去的数据json内的+ 号被直接干掉了.
后来传输之前直接先编码.
接收端:
1 public void ProcessRequest(HttpContext context) 2 { 3 ReturnResult result = new ReturnResult(); 4 var method = context.Request.QueryString["method"].ToString(); 5 6 byte[] byts = new byte[HttpContext.Current.Request.InputStream.Length]; 7 HttpContext.Current.Request.InputStream.Read(byts, 0, byts.Length); 8 string req = System.Text.Encoding.Default.GetString(byts); 9 req = HttpContext.Current.Server.UrlDecode(req); 10 11 12 //string p = @"d{4}-d{2}-d{2}sd{2}:d{2}:d{2}"; 13 //MatchEvaluator matchEvaluator = new MatchEvaluator(ConvertDateStringToJsonDate); 14 //Regex reg = new Regex(p); 15 //req = reg.Replace(req, matchEvaluator); 16 17 18 try 19 { 20 if (context.Request.Params.Count > 0) 21 { 22 23 if (!string.IsNullOrEmpty(method)) 24 { 25 switch (method) 26 { 27 28 case DTKeys.URL_PARM_METHOD_SENDMESSAGEREMIND://来自用户信息认证的 附件上传 29 ContactMsg m = JsonHelper.FromJson<ContactMsg>(req); 30 SendMessageRemind(m); 31 break; 32 33 default: 34 break; 35 } 36 } 37 } 38 else 39 { 40 result.Status = false; 41 result.Msg = "未检测的有效文件信息,或者您未登录"; 42 } 43 } 44 catch (Exception ex) 45 { 46 result.Status = false; 47 result.Msg = ex.Message; 48 Log4netHelper.WriteExceptionLog("Beta.ProductMarket.Web.Product.SendMsgToWX.ashx", ex); 49 } 50 context.Response.Clear(); 51 context.Response.ContentType = "text/html; charset=utf-8"; 52 context.Response.Write(JsonConvert.SerializeObject(result)); 53 } 54