我的目标是从内容处置标头读取和解析csv文件
我的代码:
baseUrl := "Some url that i call to fetch csv file"
client := http.Client{}
resp, _ := client.Get(baseUrl)
defer resp.Body.Close()
fmt.Println(resp)
// &{200 OK 200 HTTP/2.0 2 0 map[Content-Disposition:[attachment;filename=somefilename.csv] Content-Type:[text/csv; charset=UTF-8] Date:[Mon, 30 Sep 2019 09:54:08 GMT] Server:[Jetty(9.2.z-SNAPSHOT)] Vary:[Accept]] {0xc000530280} -1 [] false false map[] 0xc000156200 0xc0000c26e0}
如何从内容处置标头中检索此文件?
您必须消耗请求的主体。
baseUrl := "Some url that i call to fetch csv file"
client := http.Client{}
resp, _ := client.Get(baseUrl)
defer resp.Body.Close()
io.Copy(os.Stdout, resp.Body) // this line.
fmt.Println(resp)
如果必须处理多部分表格数据https://golang.org/pkg/net/http/#Request.FormFile