"http.Post" expects a "Reader" as the body argument. "File" implements "Reader". But if I pass file as the body argument I always receive 0 bytes at the other end. Why?
Here is the code:
package main
import (
"fmt"
"net/http"
"os"
)
func main() {
file, err := os.Open("lala.txt")
if err != nil {
fmt.Printf("file open errrrr %v
", err)
}
defer file.Close()
resp, err := http.Post("http://requestb.in/11fta851", "text/plain", file)
if err != nil {
fmt.Printf("errrrr %v
", err)
} else {
fmt.Printf("resp code %d
", resp.StatusCode)
}
}
I know that you could do "file.ReadAll" to a buffer and use that. But it feels like double work.