..

一个post请求例子

url := "http://127.0.0.1:4055"
contentType := "application/json"
// data := "{\"method\":\"erc_token_context\"}"

// var jsonStr = []byte(data)

var data = make(map[string]string)
data["method"] = "erc_token_context"
data["secret"] = secret
data["Account"] = account

jsonStr, _ := json.Marshal(data)

c := Post(url, jsonStr, contentType)
func Post(url string, data []byte, contentType string) (content string) {
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
	req.Header.Add("content-type", contentType)
	if err != nil {
		panic(err)
	}
	defer req.Body.Close()

	client := &http.Client{Timeout: 5 * time.Second}
	resp, error := client.Do(req)
	if error != nil {
		panic(error)
	}
	defer resp.Body.Close()

	result, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "读取 resp 错误"
	}

	var tokenContext map[string]interface{}
	err = json.Unmarshal(result, &tokenContext)
	if err != nil {
		panic("解析失败")
	}

	for k, v := range tokenContext {
		fmt.Printf(k, v)
	}

	content = string(result)

	return content
}

Nothing