douwen5690 2018-11-10 15:08
浏览 1152
已采纳

如何从gin中的前端获取数据?

To my shame, I have not been able to figure out how to get data from the frontend in Gin framework. In Django I get data So:

user=request.data.get('user')
print(user)

Everything is simple and understandable as day. How should I do it in gin?

user := c.Query("user")
user := c.Param("user")
user := c.Params.ByName("user")
user := c.PostForm("user")
println(user)//emptiness....
  • 写回答

4条回答 默认 最新

  • dongqiao8421 2018-11-15 20:31
    关注

    Server GIN can't handle routine default application/json requests from axios!!! What??? Requests should be sent as application/x-www-form-urlencoded. My decision in Vue project: Use vue-resource instead axios (axios.post=>this.$http.post) with option Vue.http.options.emulateJSON = true; in main.js

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?