二开案例.自定义HttpHandler
1、自定义HttpHandler,拿到请求的url和json进行处理,再返回json
using System.IO; using System.Text; using System.Web; namespace Test2024.HttpHandler { public class TestHandler : IHttpHandler { bool IHttpHandler.IsReusable { get { return true; } } void IHttpHandler.ProcessRequest(HttpContext context) { var request = context.Request; request.InputStream.Position = 0; StreamReader sr = new StreamReader(request.InputStream, Encoding.UTF8); var json = sr.ReadToEnd(); //只要是/TestHandler/开头的url,都会到达这里。根据url和接收到的json,返回数据。例如 /k3cloud/TestHandler/test111 var response = context.Response; response.Headers.Add("Content-Type", "application/json"); var data = new { url = request.Url.ToString(), 接收到的json = json }; var responseJson = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(data); response.Write(responseJson); response.End(); } } }
2、在Web.config中注册HttpHandler(Test24.PlugIns.BL为dll名称,Test2024.HttpHandler.TestHandler为自定义类的全名)
<httpHandlers> <add name="TestHandler" path="TestHandler/*" verb="*" type="Test2024.HttpHandler.TestHandler,Test24.PlugIns.BL" /> </httpHandlers>
3、重启IIS,访问 localhost/k3cloud/TestHandler/test111
$.ajax('/k3cloud/TestHandler/test111', { method: 'POST', contentType: "application/json" , dataType : 'json', data: {test:"123456"}, success:function (result) { console.log(result); }, error:function (err) { console.log('失败') } })
5、公有云需要通过补丁包的形式修改Web.config,参考贴子: https://wenku.my7c.com/article/433641393274277632?productLineId=1&isKnowledge=2&lang=zh-CN
二开案例.自定义HttpHandler
1、自定义HttpHandler,拿到请求的url和json进行处理,再返回jsonusing System.IO;using System.Text;using System.Web;namespace Test2024...
点击下载文档
本文2024-09-16 18:25:58发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22104.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章