我想要this异常原因:
// ErrBodyNotAllowed is returned by ResponseWriter.Write calls // when the HTTP method or response code does not permit a // body. ErrBodyNotAllowed = errors.New("http: request method or response status code does not allow body")
当我使用 fiddler 发送带有正文的 HEAD 请求时,我收到 400/504 错误代码,但我在我的应用程序中没有看到任何错误日志。
最佳答案
我假设您谈论的是您控制的围棋服务器。当您在 HEAD 请求上调用 writer.Write() 时,您应该会看到返回此错误。您需要在您的应用程序中通过检查该错误来处理它。找到调用 Write 的位置,检查错误,然后将其显示给用户。您可能需要更换:
writer.Write(data)
用类似的东西:
_,err := writer.Write(data)
关于http - 发送带有 body 的 HEAD http 请求导致 net/http 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52310889/