不为别的,只为做一个连自己都羡慕的人

go接收前端传过来的方式

get请求方式:

func marixExplainPHandler(w http.ResponseWriter,rr *http.Request){
  query := rr.URL.Query()
  id :
= query.Get("id")
}

form表单传递参数

func marixExplainPHandler(w http.ResponseWriter,rr *http.Request){
  con := rr.PostFormValue("con")
  lang := rr.PostFormValue("lang")
 }

post请求正常接收参数:

func marixExplainPHandler(w http.ResponseWriter,request *http.Request){
  decoder := json.NewDecoder(request.Body)

    // 用于存放参数key=value数据
    var params map[string]string

    // 解析参数 存入map
    decoder.Decode(&params)

    fmt.Printf("POST json: username=%s, password=%s\n", params["username"], params["password"])
 }

 

posted @ 2021-09-02 10:27  升级打怪  阅读(324)  评论(0编辑  收藏  举报