request, _ := http.NewRequest("PUT", myURL, &buf) // this works fine request.Header.Set("Content-Type", "application/octet-stream") http.DefaultClient.Do(request) 编辑:问题不在于设置ContentLength标题(即它被设置为默认值 0);这导致服务器不处理上传。使用缓冲区时,golang确实将标头设置为缓冲区...
示例代码: var curl = require('./node_curl'); var data = new Buffer('abc'); var headers = {'Content-Length': data.length}; var req = curl.request({url: 'http://weibo.com/', method: 'put', headers: headers, debug: true}); req.write(data); var ...
我的请求是向 etcd 服务器发出的,该服务器将我的所有键设置为空值。虽然这有点新颖,但几乎没有用。:)http://play.golang.org/p/pIoB--bXUTpackage mainimport ( "bytes" "fmt" "net/http" "net/http/httputil" "net/url" "strconv")func main() { put := url.Values{} put.Set("value", "...
我正在尝试发出一个简单PUT的上传文件的请求。http.NewRequest接受body(作为io.Reader)。但是传递os.Fileasbody不起作用,而首先将其读入缓冲区可以解决问题:file, _ := os.Open(filePath)// request, _ := http.NewRequest("PUT", myURL, file)// ^^^ why does this not work???var buf bytes.Bufferte...