亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未收到 Go 語言表單的數據

未收到 Go 語言表單的數據

Go
墨色風雨 2021-09-13 19:46:40
這是 astaxie 書中的簡單形式,當我嘗試 '/login' 時,我得到No Data received { Unable to load the webpage because the server sent no data.   Error code: ERR_EMPTY_RESPONSE }這是代碼:main.gopackage mainimport (    "fmt"    "html/template"    "net/http")func sayhelloName(w http.ResponseWriter, r *http.Request) {    fmt.Fprintf(w, "Hello astaxie!") // write data to response}func login(w http.ResponseWriter, r *http.Request) {    fmt.Println("method:", r.Method) //get request method    if r.Method == "GET" {      t, err :=template.New("").Parse(loginHtml)      if err != nil {          panic(err)      }      const loginHtml = `      <html>      <head>      <title></title>      </head>      <body>      <form action="/login" method="post">          Username:<input type="text" name="username">          Password:<input type="password" name="password">          <input type="submit" value="Login">      </form>      </body>      </html>      `    }    else {        r.ParseForm()        // logic part of log in        fmt.Println("username:", r.PostFormValue("username"))        fmt.Println("password:", r.PostFormValue("password"))    }}func main() {    http.HandleFunc("/", sayhelloName) // setting router rule    http.HandleFunc("/login", login)   http.ListenAndServe(":9090", nil) // setting listening port}#login.gtpl<html><head><title></title></head><body><form action="/login" method="post">    Username:<input type="text" name="username">    Password:<input type="password" name="password">    <input type="submit" value="Login"></form></body></html>Any idea??
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號