golang:模拟http post请求
package mainimport (
"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]