今天在项目组用json传输数据 post方法提交 发现传输过去的数据json内的+ 号被直接干掉了.
后来传输之前直接先编码.
接收端:
public void ProcessRequest(HttpContext context)
{
ReturnResult result = new ReturnResult();
var method = context.Request.QueryString["method"].ToString(); byte[] byts = new byte[HttpContext.Current.Request.InputStream.Length];
HttpContext.Current.Request.InputStream.Read(byts, , byts.Length);
string req = System.Text.Encoding.Default.GetString(byts);
req = HttpContext.Current.Server.UrlDecode(req); //string p = @"\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}";
//MatchEvaluator matchEvaluator = new MatchEvaluator(ConvertDateStringToJsonDate);
//Regex reg = new Regex(p);
//req = reg.Replace(req, matchEvaluator); try
{
if (context.Request.Params.Count > )
{ if (!string.IsNullOrEmpty(method))
{
switch (method)
{ case DTKeys.URL_PARM_METHOD_SENDMESSAGEREMIND://来自用户信息认证的 附件上传
ContactMsg m = JsonHelper.FromJson<ContactMsg>(req);
SendMessageRemind(m);
break; default:
break;
}
}
}
else
{
result.Status = false;
result.Msg = "未检测的有效文件信息,或者您未登录";
}
}
catch (Exception ex)
{
result.Status = false;
result.Msg = ex.Message;
Log4netHelper.WriteExceptionLog("Beta.ProductMarket.Web.Product.SendMsgToWX.ashx", ex);
}
context.Response.Clear();
context.Response.ContentType = "text/html; charset=utf-8";
context.Response.Write(JsonConvert.SerializeObject(result));
}