Go实现的http服务器(超简单

发布于 2018-12-27  10 次阅读


给大家拜个早年
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{
        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(":8000",nil);err!=nil{
        fmt.Println("ListenAndServe err",err)
    }
}

访问localhost:8000/login

得到

This is a GTE request

工事中....


inm民,无友善度