golang 搭建简单web服务器
来源:互联网 发布:mac口红代理价格表 编辑:程序博客网 时间:2024/05/16 16:04
搭建最简单的web服务器,在浏览器输入 localhost:9002/baby
会打印出 Hi, I love you baby
package mainimport ( "fmt" "net/http" "strings" "html" "io/ioutil" //"encoding/json")type Server struct { ServerName string ServerIP string}type Serverslice struct { Servers []Server ServersID string}func main() { http.HandleFunc("/", handler) http.ListenAndServe(":9002", nil)}func handler(w http.ResponseWriter, r *http.Request) { r.ParseForm() //解析参数,默认是不会解析的 fmt.Fprintf(w, "Hi, I love you %s", html.EscapeString(r.URL.Path[1:])) if r.Method == "GET" { fmt.Println("method:", r.Method) //获取请求的方法 fmt.Println("username", r.Form["username"]) fmt.Println("password", r.Form["password"]) for k, v := range r.Form { fmt.Print("key:", k, "; ") fmt.Println("val:", strings.Join(v, "")) } } else if r.Method == "POST" { result, _:= ioutil.ReadAll(r.Body) r.Body.Close() fmt.Printf("%s\n", result) } }
0 0
- golang 搭建简单web服务器
- GoLang之搭建Web服务器
- 使用Golang 搭建http web服务器
- 使用Golang 搭建http web服务器
- 使用Golang 搭建http web服务器
- 使用golang 搭建http web服务器
- 基于Docker和Golang搭建Web服务器
- 搭建简单的Web服务器
- Golang实战【web服务器】
- 搭建web服务器之Apache服务器简单搭建过程记录
- 用netcat搭建简单web服务器
- go搭建一个简单web服务器
- nodejs搭建web服务器就是这么简单!
- 搭建一个简单的Go Web服务器
- node-web服务器简单搭建
- 简单搭建centos7的web服务器
- Golang http 建立Web服务器
- Golang编写简单图片服务器
- CK,KNN算法
- informatica体系结构
- linux内核中jiffies的回绕问题
- javax.persistence 注释注解
- RT 降维技术
- golang 搭建简单web服务器
- mysql 三个函数
- 权限系统与UI交互心得
- play! 关于在 Eclipse 中找不到 CRUD 类的解决办法
- 有道词典 Andriod 版本数据格式分析
- 自考路上,我们更加精彩
- HDU2825 Wireless Password【AC自动机】
- CSV数据导入Parquet表
- java语言实现创建型模式—简单工厂模式