首页 > 其他 > 详细

go接收前端传过来的方式

时间:2021-09-02 16:16:55      阅读:27      评论:0      收藏:0      [点我收藏+]

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"])
 }

 

go接收前端传过来的方式

原文:https://www.cnblogs.com/lxz123/p/15217618.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!