02.go搭建一个web服务器
2017-12-28 11:07
549 查看
接收get、post消息
浏览器测试地址 http://localhost:9000/login
package main
import (
"fmt"
"net/http"
)
func login(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Println(r.Method)
if r.Method == "GET"
{
fmt.Fprintf(w, "This is a GET request")
}
else if r.Method == "POST"
{
fmt.Fprintf(w, "This is a POST request")
}
else {
w.Header().Set("Access-Control-Allow-Origin", "*")
fmt.Println("Recived info:", r.Form)
fmt.Fprintf(w, r.Form.Get("info"))
}
}
func main() {
http.HandleFunc("/login", login)
if err := http.ListenAndServe(":9000", nil); err != nil {
fmt.Println("ListenAndServe err", err)
}
}
浏览器测试地址 http://localhost:9000/login
package main
import (
"fmt"
"net/http"
)
func login(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Println(r.Method)
if r.Method == "GET"
{
fmt.Fprintf(w, "This is a GET request")
}
else if r.Method == "POST"
{
fmt.Fprintf(w, "This is a POST request")
}
else {
w.Header().Set("Access-Control-Allow-Origin", "*")
fmt.Println("Recived info:", r.Form)
fmt.Fprintf(w, r.Form.Get("info"))
}
}
func main() {
http.HandleFunc("/login", login)
if err := http.ListenAndServe(":9000", nil); err != nil {
fmt.Println("ListenAndServe err", err)
}
}
相关文章推荐
- GO搭建一个web服务器
- Go搭建一个web服务器
- Go 搭建一个Web 服务器(1):IOC工厂
- Go语言进行web开发(一) 搭建一个简单的web服务器
- Go搭建一个Web服务器
- go搭建一个简单web服务器
- 搭建一个简单的Go Web服务器
- 分享一个python 的小功能:搭建一个本地web服务器
- 使用go的http包建立一个简单的web 服务器
- web前端进阶02:初学nodeJS之http系统模块使用 (写一个http请求的服务器)
- node.js搭建一个自己的本地web服务器
- 用Go+Vue.js快速搭建一个Web应用(初级demo)
- 在本机环境中搭建一个真正的web网站环境(和网站部署到服务器上效果一致)
- go语言 通过http包搭建简单web服务器 对http包源码的略微分析
- 个人用户如何搭建一个全面的WEB服务器(中)
- 个人用户如何搭建一个全面的WEB服务器(中)
- 使用nodejs搭建一个简单的web服务器
- 三分钟使用webpack-dev-sever搭建一个服务器
- mac端如何快速搭建一个web服务器
- VPS -Digital Ocean -搭建一个最简单的web服务器