golang模拟post请求

使用golang模拟post请求,首先用map封装数据,然后通过json.marshal方法转化成为[]byte类型,最后使用http.post方法

func main() {
	config := map[string]interface{}{}
	config["Id"] = 0
	config["afa"] = "input"
	config["afa"] = 2
	configdata, _ := json.Marshal(config)
	fmt.Println(config)
	body := bytes.NewBuffer([]byte(configdata))
	resp, err := http.Post("http://localhost:8080/vOne", "application/json;charset=utf-8", body)
	fmt.Println(resp,err)

}

猜你喜欢

转载自blog.csdn.net/qq_30505673/article/details/90116205