前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【小5聊】C#基础之Response.ContentType响应内容类型[通俗易懂]

【小5聊】C#基础之Response.ContentType响应内容类型[通俗易懂]

作者头像
全栈程序员站长
发布2022-09-09 10:46:27
1.5K0
发布2022-09-09 10:46:27
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

【开发环境】 开发系统:Windows 10 开发平台:.Net Framework 4.6.1(系统框架) 开发语言:C# 文章作用:记录、备忘、总结、分享、理解

1、实际应用测试,代码如下

代码语言:javascript
复制
#region 测试
public void Test()
{
    //Response.ContentType = "application/json";
    Response.Write("{\"code\":\"200\",\"message\":\"测试信息\"}");
}
#endregion

2、使用Postman工具调用接口,效果如下

【小5聊】C#基础之Response.ContentType响应内容类型[通俗易懂]
【小5聊】C#基础之Response.ContentType响应内容类型[通俗易懂]

3、设置响应内容类型改为json类型,效果如下

【小5聊】C#基础之Response.ContentType响应内容类型[通俗易懂]
【小5聊】C#基础之Response.ContentType响应内容类型[通俗易懂]
【小5聊】C#基础之Response.ContentType响应内容类型[通俗易懂]
【小5聊】C#基础之Response.ContentType响应内容类型[通俗易懂]

Response.ContentType

1、文本格式:html、xml、txt

Response.ContentType = “text/html “;

Response.ContentType = “text/xml”;

Response.ContentType = “text/plain”;

2、图片格式

Response.ContentType = “image/jpg”;

Response.ContentType = “image/png”;

Response.ContentType = “image/gif”;

3、媒体格式

Response.ContentType = “application/json”; //比较常用

Response.ContentType = “application/xml”;

Response.ContentType = “application/xhtml+xml”;

Response.ContentType = “application/atom+xml”;

Response.ContentType = “application/pdf”;

Response.ContentType = “application/msword”;

Response.ContentType = “application/octet-steam”;

Response.ContentType = “application/x-www-form-urlencoded”;

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/161605.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档