噜噜哒
我是这样做的。func SendPostRequest(url string, filename string) (string, []byte) { api_key := ReadAPIKey("../.api_key") client := &http.Client{} data, err := os.Open(filename) if err != nil { log.Fatal(err) } req, err := http.NewRequest("POST", url, data) if err != nil { log.Fatal(err) } req.SetBasicAuth("api", api_key) resp, err := client.Do(req) if err != nil { log.Fatal(err) } content, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } return resp.Status, content}func main() { status, content := SendPostRequest("https://api.example.com/upload", "test.jpg") fmt.Println(status) fmt.Println(string(content))}