go 简单post请求

 

 

 

   json 请求

    client := &http.Client{}
    data := make(map[string]interface{})
    data["key_name"] = key_name
    data["value_name"] = key_value
    bytesData, _ := json.Marshal(data)
    req, _ := http.NewRequest("POST", "http://url", bytes.NewReader(bytesData))
    req.Header.Set("Content-Type", "application/json")
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    body, _ := ioutil.ReadAll(resp.Body)
    log.Println(string(body))

 

posted @ 2023-02-13 16:10  AngDH  阅读(43)  评论(0编辑  收藏  举报