// hello
package main
import (
"fmt"
"log"
"net/http"
"strings"
)
func sayHelloName(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Println(r.Form)
fmt.Println("path: ", r.URL.Path)
fmt.Println("scheme: ", r.URL.Scheme)
fmt.Println(r.Form["url_log"])
for k, v := range r.Form {
fmt.Println("key: ", k)
fmt.Println("val: ", strings.Join(v, ""))
}
fmt.Fprintf(w, "Hello World")
}
func main() {
http.HandleFunc("/", sayHelloName)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServer: ", err)
}
}
编译以上代码, 然后运行.exe 文件,启动WEB 服务器
在本地浏览器上访问: http://localhost:9090 ,页面将会显示Hello World