的Java jsoup ignoreContentType
有解析响应时忽略文档的Content-Type
。
Go中的ResponseWriter
默认会将最初512字节的写入数据传递给DetectContentType
的结果添加一个Content-Type集合。
您可以实现自己的ResponseWriter
,你设定自己的Content-Type
到""
以忽略响应的数据推导出任何(可能是不正确的)内容类型。
func (writer MyOwnResponseWriter) Write(data []byte) (int, error) {
writer.Header().Set("Content-Type", "")
return len(data), nil
}
JimB建议in the comments简单地设置自己的内容类型,为server.go
包括:
//If the Header does not contain a Content-Type line,
// Write adds a Content-Type set to the result of
// passing the initial 512 bytes of written data toDetectContentType.
你为什么试图忽略内容类型? Content-Type是否导致您在代码中出现问题?如果是的话,你得到的错误是什么? – 2016-12-29 08:52:54
没有错误返回,我会发表另一条评论来解释。 – henghanan