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

Golang web 隐藏真实文件地址?

andyxiaqi · · 1445 次点击
我想访问GO web 某个地址然后是下载文件。 例如我访问: http://127.0.0.1/public/image/img1 这个地址,然后下载文件,跟访问这个一样: http://127.0.0.1/public/image.jpg
``` package main import ( "io/ioutil" "log" "net/http" ) func main() { http.HandleFunc("/public/image/img1", a) err := http.ListenAndServe(":8080", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } } func a(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "image/jpeg") b, _ := ioutil.ReadFile("a.png") w.Write(b) } ```
#3
更多评论
是返回文件呀,主要是下载
#2

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中