myhttp.go 
package main
import (
"fmt"
"html/template"
"log"
"net/http"
)
func login(w http.ResponseWriter,r *http.Request) {
fmt.Println("method:",r.Method)
if r.Method == "GET" {
t,_ :=template.ParseFiles("login.html")
t.Execute(w,nil)
} else {
fmt.Println("username:",r.Form["username"])
fmt.Println("password:",r.Form["password"])
}
}
func main() {
http.HandleFunc("/login",login)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServe:",err)
}
}

如上代码 login.html要和生成的可执行文件myhttp.exe在同一级目录


相关文章:

  • 2021-05-26
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2021-10-27
  • 2021-12-07
猜你喜欢
  • 2022-12-23
  • 2021-11-27
  • 2021-09-07
  • 2021-12-27
  • 2022-02-07
  • 2021-12-11
  • 2021-11-27
相关资源
相似解决方案