1. 首页
  2. 主题
  3. Go问与答

go搭建的服务器 局域网内和本机ip都无法访问

XiaoZhangJian · · 5400 次点击
问题:使用http包搭建本地服务器,使用本机ip:端口 无法访问,同局域网内也无法访问该服务器 代码: ``` package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/", HelloHandler) http.ListenAndServe(":8000", nil) // 或者 http.ListenAndServe("0.0.0.0:8000", nil) } func HelloHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "hello world") } ``` 127.0.0.1:8000、 localhost:8000、 0.0.0.0:8000、 都好使 本机ip :8000 访问不行 萌新 求各位大佬们指导 :smiley:
http.ListenAndServe("0.0.0.0:8000", nil) 换成 http.ListenAndServe(":8000", nil) }
#1
更多评论
不好使,我都试过了 这两种方式
#2
代码没问题,我测试了,检查你的局域网是否互通。
#3

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中