youbo1 发表于 2018-9-21 07:12:02

golang:模拟http post请求

package main  

  
import (
  "net/http"
  "io/ioutil"
  "fmt"
  
)
  

  
func main(){
  //设置路由和接收HTTP请求的方法
  mux :=http.NewServeMux()
  mux.HandleFunc("/msg",recvHandle)
  //设置http服务
  server :=&http.Server{
  Addr:    "0.0.0.0:8090",
  Handler: mux,
  }
  //启动监听
  server.ListenAndServe()
  
}
  
func recvHandle(w http.ResponseWriter, r *http.Request){
  body,_ :=ioutil.ReadAll(r.Body)
  fmt.Println(string(body))
  fmt.Fprintf(w,"3q your msg.")
  
}
  



页: [1]
查看完整版本: golang:模拟http post请求