什么是 HTTP 标头?什么是字符集?

发布于 2024-11-03 11:09:51 字数 108 浏览 7 评论 0原文

我对编码以及 PHP 和 XHTML 领域都是新手。我只是浏览元标记的详细信息,不了解 http-equiv 属性,也不了解所使用的字符集以及 UTF-8 值所指的内容,例如

I am new to the world of coding as well as PHP and XHTML. I was just going through the details of meta tags and do not understand the property http-equiv nor what is the charset used for as well as what the value UTF-8 refers to e.g. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪花飘飘的天空 2024-11-10 11:09:51

Joel Spolsky 有一篇非常好的文章讨论了字符集。看一下:

每个软件开发人员绝对必须了解 Unicode 和字符集的绝对最低限度(没有任何借口) !)

至于 HTTP 标头,在 Google 上快速搜索“理解 HTTP 标头”会发现很多描述它们的好文章。这里有一个:傻瓜式 HTTP 标头

简而言之,HTTP 标头基本上是发送到用户 Web 浏览器的小消息,告诉浏览器它将接收到的输出(即,它是网页、文件还是图像;是否应该缓存;等等) ,或者像 cookie 这样应该由客户端浏览器保存的东西。

HTTP 标头也从用户的 Web 浏览器发送回服务器。最明显的例子还是 cookie——浏览器保存的每个 cookie 都应该在每个 HTTP 请求上发送回服务器。

就您而言,您可能正在谈论定义页面字符集的特定 HTTP 标头。 标签用于模拟 HTTP 标头。

例如,如果您有一个静态 HTML 页面并希望利用特定的 HTTP 标头,但无法在 Web 服务器中配置它,则可以使用 标签来达到相同的结果。

There's a really good article by Joel Spolsky that discusses charsets. Take a look:

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

As for HTTP headers, a quick Google search for "understanding HTTP headers" turned up quite a few good articles that describe them. Here's one: HTTP Headers for Dummies.

In short, HTTP headers are basically small messages that get sent to the user's web browser that tell the browser about the output it's going to receive (ie, is it a web page, a file, an image; should it be cached; etc), or for things like cookies that should be saved by the client's browser.

HTTP headers are also sent from the user's web browser back to the server. The most obvious example are again, cookies - every cookie that is saved by the browser is supposed to be sent back to the server on each HTTP request.

In your case, you're probably talking about a specific HTTP header that defines the character set for the page. The <meta http-equiv=""> tags are used to simulate HTTP headers.

For example, if you had a static HTML page and wanted to take advantage of a particular HTTP header, but couldn't configure it in the web server, you could use a <meta http-equiv=""> tag to achieve the same result.

乞讨 2024-11-10 11:09:51

@Ryan:很好的链接。我希望 12 年前在我开始大规模的国际 CMS 实施之前就读过这篇文章。

简单来说,当浏览器收到 HTTP 响应流(所请求的网页)时,它看到的只是一个字节序列。由于字节可以表示不同的字符,具体取决于服务器使用的编码,因此浏览器在解释字节流时使用元标记中指定的编码非常重要。如果服务器使用的编码与元标记中的编码不同,您将看到乱码。

相反,与网页 POST 关联的 HTTP 请求也具有由浏览器透明提供的编码,因为服务器需要知道如何解释发送的任何表单数据。

@Ryan: Great link. I wish I had read the article 12 years ago before I embarked on a large international CMS implementation.

In simple terms, when the browser receives an HTTP response stream (the web page that was requested), all it sees is a sequence of bytes. Because bytes can mean different characters, depending on the encoding that was used by the server, it is very important that the browser uses the encoding specified in the meta tag when interpreting the byte stream. If the server used a different encoding than what it put in the meta tag, you will see gibberish.

Conversely, the HTTP request associated with a web page POST also has an encoding that is provided transparently by the browser, because the server needs to know how to interpret any form data that was sent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文