“http.Post”需要一个“Reader”作为主体参数。“文件”实现“阅读器”。但是如果我将文件作为 body 参数传递,我总是在另一端收到 0 个字节。为什么?这是代码:package mainimport ( "fmt" "net/http" "os")func main() { file, err := os.Open("lala.txt") if err != nil { fmt.Printf("file open errrrr %v \n", err) } defer file.Close() resp, err := http.Post("http://requestb.in/11fta851", "text/plain", file) if err != nil { fmt.Printf("errrrr %v \n", err) } else { fmt.Printf("resp code %d \n", resp.StatusCode) }}我知道您可以对缓冲区执行“file.ReadAll”并使用它。但感觉像是双重工作。
1 回答
- 1 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消