18910140161

golang:头内容类型为两行

顺晟科技

2021-09-02 12:26:46

77

一个Golang练习要求我加载一个本地文件并在浏览器中显示它。然而,我得到的不是图片,而是纯文本。 Chrome检查器告诉我:

Content-Length: 55
Content-Type: : text/html; charset=utf-8
Content-Type: text/plain; charset=utf-8
Date: Thu, 02 Sep 2021 04:12:14 GMT

但是我的代码是显式的:

package main

import (
    "io"
    "net/http"
)

func main() {
    http.HandleFunc("/hedgehog", hedgehog)
    http.ListenAndServe(":8080", nil)
}

func hedgehog(w http.ResponseWriter, req *http.Request) {
    w.Header().Set("Content-Type: ", "text/html; charset=utf-8")

    io.WriteString(w, `
    <!--Internally served-->
    <img src="/herisson.jpeg">
    `)
}

我已经检查了main.go和herisson.jpeg文件在同一个文件夹中。 关闭终端并重新启动后,关闭浏览器,清空缓冲区,没有变化。


顺晟科技:

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航