WebAPI 返回Html,js
来源:互联网 发布:mysql全文检索 编辑:程序博客网 时间:2024/06/07 15:55
这两天在工作中遇到一个需求,因为我们做的是JS插件,因此所有的功能都通过WebAPI来实现,但最初用到WebAPI都是用来传输数据的,这次却要获取Html页面,JS还有一些其他文件,后来细细研究了一下,其实也不难,只要返回值部分写好,应该没什么问题,主要代码如下:
获取Html
public HttpResponseMessage GetHtml() { //需要加载的html页面的路径 var path = “...”; var httpResponseMessage = new HttpResponseMessage(); httpResponseMessage.Content = new StringContent(File.ReadAllText(path), Encoding.UTF8); httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return httpResponseMessage; }
获取JS
[HttpGet] public HttpResponseMessage GetJS(string file) { //需要加载的JS路径 var path =“...”; var httpResponseMessage = new HttpResponseMessage(); httpResponseMessage.Content = new StringContent(File.ReadAllText(path), Encoding.UTF8); httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("text/javascript"); return httpResponseMessage; }
阅读全文
0 0
- WebAPI 返回Html,js
- Mvc4 WebApi 返回 格式
- WebApi返回Json
- WebAPI返回404
- WebApi 返回格式修改
- WebAPI返回一个List
- Django返回html和js代码
- 让WEBAPI始终返回JSON格式数据
- webapi 返回数据类型控制(json,xml)
- 修改 mvc webapi 默认返回 json 格式
- ASP.Net WebAPI的返回值
- webapi返回泛型给easyui
- c# 【MVC】WebApi设置返回Json
- .net MVC5 webAPI 返回json设置
- webapi返回的json数据出现k__BackingField
- 让webapi统一返回JSON数据格式
- .net mvc4 Webapi Rest接口返回值
- c# WebApi之接口返回类型详解
- MySQL-02-windows下查看frm,myi,myd
- log4j2应用详解
- 使用Toad调用expdp数据泵备份数据步骤及注意事项
- linux 学习系列-Linux 用户和用户组管理
- 权限管理命令chgrp
- WebAPI 返回Html,js
- solr杂记
- Uncaught SyntaxError: missing ) after argument list
- php的垃圾回收机制——引用计数
- align="absmiddle"是什么居中?其它的居中方式有哪些?
- linux NFS服务器的安装与配置
- MyJDBC驱动程序说明文档
- linux shell shift
- mysql 的my.ini文件