dougao9864 2016-12-01 11:53
浏览 760

发送带有参数的GET请求时获取301状态代码

I have a very simple Go server code setup with mux and when I use curl with GET request params (localhost:8080/suggestions/?locale=en), I get 301 status code (Move permanently). But when there's no get parameters, it's working just fine.

func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/suggestions", handleSuggestions).Methods("GET")
log.Fatal(http.ListenAndServe("localhost:8080", router))
}

Can somebody shed me a light on this.Thanks

  • 写回答

2条回答 默认 最新

  • dongliyu3278 2016-12-01 12:41
    关注

    That's simply because you registered the path /suggestions (note: there is no trailing slash), and you call the URL localhost:8080/suggestions/?locale=en (there is a trailing slash after /suggestions).

    You router detects that there's a registered path which would match the requested path without the trailing slash (based on your Router.StrictSlash() policy), so it sends a redirect which when followed would lead you to a valid, registered path.

    Simply use a URL without trailing slash after suggestions:

    localhost:8080/suggestions?locale=en
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)