package main import ( "net/http" "net/url" "fmt" "io/ioutil" _ "io" "bytes" ) func main() { postFile() } func post() { //这是一个Post 参数会被返回的地址 strinUrl:="http://localhost:8080/aaa"`这里写代码片` resopne,err:= http.PostForm(strinUrl,url.Values{"num":{"456"},"num1":{"123"}}) if err !=nil { fmt.Println("err=",err) } defer func() { resopne.Body.Close() fmt.Println("finish") }() body,err:=ioutil.ReadAll(resopne.Body) if err!=nil { fmt.Println(" post err=",err) } fmt.Println(string(body)) } func postFile(){ //这是一个Post 参数会被返回的地址 strinUrl:="http://localhost:8080/aaa" byte,err:=ioutil.ReadFile("post.txt") resopne,err :=http.Post(strinUrl,"multipart/form-data",bytes.NewReader(byte)) if err !=nil { fmt.Println("err=",err) } defer func() { resopne.Body.Close() fmt.Println("finish") }() body,err:=ioutil.ReadAll(resopne.Body) if err!=nil { fmt.Println(" post err=",err) } fmt.Println(string(body)) }
查看更多关于go Http Post 发送文件流的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did31944