我今天遇到了一种奇怪的行为。说,我有一个localhost和几个文本文件。通常我会输入localhost/myfile.txt
,浏览器会显示内容。但相反,每个浏览器都会要求我下载该文件。
文本文件内容很简单,只是像这样的一堆随机字符
dasddasd dasdasd sdas dsad 122323
使用Firefox控制台我读了以下错误消息:
The character encoding of the plain text document was not declared.
The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range.
The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
当然我已经将Notepad ++中的字符编码更改为UTF-8或UTF-8而没有BOM。没有成功!
答案 0 :(得分:0)
看起来需要在HTTP标头中指定字符编码。如果您正在使用Apache,可以尝试将其添加到httpd.conf:
AddDefaultCharset utf-8