我试图通过Go发布内容到nginx服务器。我核实,我能够正确发布通过卷曲这样的内容,特别是使用下面的命令:Getting Go的HTTP post来模拟curl -d
$ curl http://example.com/myendpoint -d "Some Text"
我能看到这个帖子,并正确处理它。但是,当我尝试使用Go执行POST时,它会被服务器拒绝。在nginx的访问日志,我看到这两条线:
127.0.0.1 - - [30/Jan/2014:05:57:34 +0000] "POST /myendpoint HTTP/1.1" 400 0 "-" "Go 1.1 package http"
127.0.0.1 - - [30/Jan/2014:05:57:39 +0000] "Some Text" 400 172 "-" "-"
,我已经试过代码如下:
r, err := http.Post(uri, "application/x-www-form-urlencoded", bytes.NewReader(data))
if err != nil {
log.Printf("HTTP NOTIFICATION ERROR: %s\n", err)
return
}
r.Body.Close()
有什么,我做错了什么?谢谢!
我认为这只是整体代码的一部分,所以如果推迟r.Body.Close()'? – bishop
@bishop:不幸的是,这并没有帮助解决问题。我上面粘贴的代码是在它自己的函数中,它实际上已经分离成一个单独的goroutine。 –