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))
}