zoukankan      html  css  js  c++  java
  • 【转】Asp.net中Response.Charset 与Response.ContentEncoding区别

    Response.Charset
    ASP.NET 中示例:
    <%@ Page CodePage=936 %>
    CodePage 告诉 IIS 按什么编码来读取 QueryString,按什么编码转换数据库中的内容……

    Response.ContentEncoding

    获取或设置输出流的 HTTP 字符集。

    Response.Charset

    获取或设置输出流的 HTTP 字符集。微软对 ContentEncoding、Charset 的解释是一字不差,其实可以这样理解:ContentEncoding 是标识这个内容是什么编码的,而 Charset 是告诉客户端怎么显示的。

    我们可以做一个实验来理解:

    实验1.

    Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
    Response.Charset = "utf-8";
    Response.Write("千一网络");
    然后用浏览器打开网页,可以发现是乱码,可是用记事本查看源文件,又发现不是乱码。这就说明了:ContentEncoding 是管字节流到文本的,而 Charset 是管在浏览器中显示的。

    实验2.

    Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
    通过 Fidller,发现 HTTP 头中是:text/html; charset=gb2312。说明没有指定 Charset 时,就用 ContentEncoding 的 Charset 作为 charset。

    实验3.

    Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
    Response.Charset = "123-8";
    HTTP 头中是:text/html; charset=123-8。网页显示正常,说明如果 charset 错误,仍然以 ContentEncoding 的 Charset 作为 charset。

    实验4.

    Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
    Response.Charset = "";
    HTTP 头中是:text/html;。HTTP 头中没有 charset,网页显示正常,说明 HTTP 头中没有 charset,仍然以 ContentEncoding 的 Charset 作为 charset。

  • 相关阅读:
    gitbook
    Goland IDE使用
    go-zero RPC 框架安装 (goctl安装, protoc安装, etcd安装)
    go 打包部署
    GO redis
    go 常见异常
    go 异常处理
    go常用数据处理 (json, map, 结构体)
    Kafka日志消息
    【leetcode_easy_math】1317. Convert Integer to the Sum of Two No-Zero Integers
  • 原文地址:https://www.cnblogs.com/SALIN/p/2799912.html
Copyright © 2011-2022 走看看