63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using KJD_Web.BLL.WXXD;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.Http.Controllers;
|
|
|
|
namespace KJD_Web.Controllers
|
|
{
|
|
public class AsmxApiController : ApiController
|
|
{
|
|
//public override System.Threading.Tasks.Task<HttpResponseMessage> ExecuteAsync(
|
|
//HttpControllerContext controllerContext,
|
|
//System.Threading.CancellationToken cancellationToken)
|
|
//{
|
|
// // 把 POST 请求的 HTTP 方法临时改成 GET,绕过动词匹配
|
|
// if (controllerContext.Request.Method == HttpMethod.Post)
|
|
// {
|
|
// controllerContext.Request.Method = HttpMethod.Get;
|
|
// }
|
|
|
|
// return base.ExecuteAsync(controllerContext, cancellationToken);
|
|
//}
|
|
protected string GetRequestJsonString()
|
|
{
|
|
//Context.Response.ContentType = "text/html;charset=utf-8";
|
|
//Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
|
|
|
|
using (Stream s = HttpContext.Current.Request.InputStream) // 获得json 字符流
|
|
{
|
|
// 还原数据流
|
|
byte[] b = new byte[s.Length];
|
|
s.Read(b, 0, (int)s.Length);
|
|
string jsonText = Encoding.UTF8.GetString(b); // JSON字符串
|
|
if (string.IsNullOrEmpty(jsonText))
|
|
{
|
|
var qs = HttpContext.Current.Request.QueryString;
|
|
if (qs != null && qs.Keys.Count > 0)
|
|
{
|
|
jsonText = "{";
|
|
foreach (var key in qs.Keys)
|
|
{
|
|
jsonText += "\"" + key + "\":" + "\"" + qs[key.ToString()] + "\";";
|
|
}
|
|
jsonText = jsonText.TrimEnd(';') + "}";
|
|
}
|
|
}
|
|
return jsonText;
|
|
}
|
|
}
|
|
protected IHttpActionResult JsonString(string result)
|
|
{
|
|
var response = Request.CreateResponse(HttpStatusCode.OK);
|
|
response.Content = new StringContent(result, Encoding.UTF8, "text/html");
|
|
return base.ResponseMessage(response);
|
|
}
|
|
}
|
|
} |