dongtang4954 2018-08-16 06:30
浏览 45

在golang中发布数据后,将用户重定向回相同的URL

I want to redirect user to the page that he has came from after serving a form and taking the input from that form upon successful submission he has to redirect to the same page.

I want this to be done in Golang. Thanks in Advance

  • 写回答

1条回答 默认 最新

  • dongmou1964 2018-08-16 07:04
    关注

    You can use

    http.Redirect(w, r, r.Header.Get("Referer"), 302)
    

    r.Header.Get("Referer") always contains the referring url for current page ( which is previous url)

    Update

    As you have said in comment that your are using same url for post and get. In that case it will be update the get url as your refer url.

    In this situation you can pass the url as parameter so on success you can redirect user to that url.

    For example, If, user gets redirect to the upload page from home page then make url like this,

    http://example.com/upload?redir=http://example.com/home

    So now you have knowladge from which page the user was landed this page just redirect it to the redir url you got from url.

     redirect_url = r.FormValue("redir)
     http.Redirect(w, r, redirect_url , 302)
    
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源