mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
增加ghttp下载文件示例
This commit is contained in:
@ -8,6 +8,11 @@ import (
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.BindHandler("/download", func(r *ghttp.Request){
|
||||
r.Response.Header().Set("Content-Type", "text/html;charset=utf-8");
|
||||
r.Response.Header().Set("Content-type", "application/force-download");
|
||||
r.Response.Header().Set("Content-Type", "application/octet-stream");
|
||||
r.Response.Header().Set("Accept-Ranges", "bytes");
|
||||
r.Response.Header().Set("Content-Disposition", "attachment;filename=\"下载文件名称.txt\"");
|
||||
r.Response.ServeFile("text.txt")
|
||||
})
|
||||
s.SetPort(8199)
|
||||
|
||||
Reference in New Issue
Block a user