douming4359 2013-09-03 13:14
浏览 9
已采纳

Go Web服务器无法正确处理/ delete /模式[关闭]

I just played with a google GO official example Writing Web Applications I tried to add a functionality to delete pages and it has not worked. The reason is that if you pass "/delete/" as a parameter to http.HandleFunc() function you get always 404 Page not found. Any other "foobar" string works as expected.

Simplified code:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "%s", r.URL.Path)
}

func main() {
    http.HandleFunc("/hello/", handler)
    //http.HandleFunc("/delete/", handler)
    http.ListenAndServe(":8080", nil)
}

Steps to reproduce:

  1. Compile and call http://localhost:8080/hello/world from a browser
  2. Output is /hello/world
  3. Now comment http.HandleFunc("/hello/", handler) and uncomment http.HandleFunc("/delete/", handler)
  4. Compile and call http://localhost:8080/delete/world from a browser
  5. Result is 404 page not found, expected /delete/world

Question: Is there any special meaning for "/delete/" pattern? Is there any technical reason for that or is it just a bug?

  • 写回答

1条回答 默认 最新

  • dongzhong1929 2013-09-03 13:28
    关注

    This works fine here, and it cannot possibly work in one situation and not the other. You're just changing the string "hello" for the string "delete" between the two lines.

    I suggest trying again more carefully. It must be a detail elsewhere.


    The real reason was not checking the error result of ListenAndServe. An old copy was running in background, and the lack of error handling made it go unperceived. The browser was getting results from an old server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 ceph的对象、块、文件相关问题求解答
  • ¥50 如果使用python进行ERA5 10米风场预报检验
  • ¥15 navicat解析mysql密码
  • ¥15 SDAPI(关键词-table)
  • ¥15 unity安卓打包出现问题
  • ¥15 爱快路由器端口更改错误导致无法访问
  • ¥20 安装catkin时遇到了如下问题请问该如何解决呢
  • ¥15 VAE模型如何输出结果
  • ¥15 编译python程序为pyd文件报错:{"source code string cannot contain null bytes"
  • ¥20 关于#r语言#的问题:广义加行模型拟合曲线后如何求拐点
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部