func httppost() { data :=`{"type":"10","msg":"hello."}` request, _ := http.NewRequest("POST", "http://0.0.0.0:8090/msg", strings.NewReader(data)) //post数据并接收http响应 resp,err :=http.DefaultClient.Do(request) if err!=nil{ fmt.Printf("post data error:%v\\n",err) }else { fmt.Println("post a data successful.") respBody,_ :=ioutil.ReadAll(resp.Body) fmt.Printf("response data:%v\\n",string(respBody)) } }
golang:模拟http post请求
最新推荐文章于 2024-03-31 10:45:28 发布