今天在項目組用json傳輸資料 post方法送出 發現傳輸過去的資料json内的+ 号被直接幹掉了.
後來傳輸之前直接先編碼.
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnLyMDN4kTOyAjNtkDMzIzMzADMxYjM3AjNxAjMtYTN1kTOy8CX3AjNxAjMvwlN1UTO5IzLcd2bsJ2Lc12bj5ycn9Gbi52YuUTMwIzcldWYtl2Lc9CX6MHc0RHaiojIsJye.png)
接收端:
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}\s\d{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
轉載于:https://www.cnblogs.com/benbenfishfish/p/5706383.html