golang 原生http post 请求

时间:2019-12-11 15:48:28   收藏:0   阅读:135
        reqUrl := "###" //请求url
	content := ""
        cType := ""

	resp, err := http.PostForm(reqUrl, url.Values{"参数1": {content}, "参数2": {cType}})
	
	
	if resp != nil {
		defer func() {
			e := resp.Body.Close()
			fmt.Println(e)
		}()
	}

	

	body, err := ioutil.ReadAll(resp.Body)
	fmt.Println("body...................", string(body))
	if err != nil {
		fmt.Println("readall err..........", err)
		return false
	}

	p := make(map[string]interface{})

	err = json.Unmarshal(body, &p)
	if err != nil {
		fmt.Println("Unmarshal err,,,,,,,,,,,,,", err)
		
	}

	

	i2 := p["data"].(map[string]interface{})

	code := i2["code"]

	

  

原文:https://www.cnblogs.com/shijiu520/p/12022736.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!