大家好,又见面了,我是你们的朋友全栈君。
【开发环境】 开发系统:Windows 10 开发平台:.Net Framework 4.6.1(系统框架) 开发语言:C# 文章作用:记录、备忘、总结、分享、理解
1、实际应用测试,代码如下
#region 测试
public void Test()
{
//Response.ContentType = "application/json";
Response.Write("{\"code\":\"200\",\"message\":\"测试信息\"}");
}
#endregion
2、使用Postman工具调用接口,效果如下
3、设置响应内容类型改为json类型,效果如下
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