最近项目中用到Go来写websocket,然后顺便看看Go web。
package main
import (
. "fmt"
"net/http"
"log"
)
func sayHelloName(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
Println(r)
Println("Methods:",r.Method)
if r.Method == "POST" {
Println("username:",r.Form["username"])
Println("password:",r.Form["password"])
}else{
Println(1)
}
}
func main() {
http.HandleFunc("/", sayHelloName) // 设置路由
err := http.ListenAndServe(":9090", nil) // 设置监听端口
if err != nil {
log.Fatal("LinstenAndServer:", err)
}
}
但是为什么Postman的Foemdata中的参数Go解析不了呢?必须要用网页的才行?
Tags: None