http - 发送带有 body 的 HEAD http 请求导致 net/http 错误

标签 http go error-handling

我想要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/

相关文章:

javascript - application/xml 与 text/xml 内容类型

Java http 调用返回响应代码 : 501

json - this.input.get() 不起作用 beego

java - 如何使用 Spring RestTemplate 压缩 HTTP 请求?

java - 如何解决java.lang.ClassNotFoundException :org. apache.camel.http.common.HttpOperationFailedException

logging - 从 goroutines 写入 STDOUT 时避免困惑的输出

go - 利用goroutines和channel进行从上到下的树构建功能

jquery - 在 ASP.NET MVC 4 中通过 ajax 在客户端显示服务器端模型状态错误

logging - InstallAnywhere 如何在 install.log 中将错误分类为致命和非致命?

postgresql - Go pq 和 Postgres 对约束进行适当的错误处理