golang 原生http post 请求

        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"]

	

  

猜你喜欢

转载自www.cnblogs.com/shijiu520/p/12022736.html