go 的入门之路 http post 请求

来源:互联网 发布:simulink典型算法模型 编辑:程序博客网 时间:2024/04/28 02:18
import ("net/http""net/url""fmt""io/ioutil")func main()  {post()}func post()  {//这是一个Post 参数会被返回的地址strinUrl:="http://localhost:8080/aaa"resopne,err:=http.PostForm(strinUrl,url.Values{"num":{"456"}})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))}
运行的结果;Key = num, Value = [456]

原创粉丝点击