1,发送http post请求(客户端)
func httppost() {
data :=`{"type":"10","msg":"hello."}`
request, _ := http.NewRequest("POST", "https://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))
}
}
func httppost() {