go 表单
Posted lajiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go 表单相关的知识,希望对你有一定的参考价值。
package main
import (
"fmt"
"io"
"net/http"
)
const form = `<html><body><form action="#" method="post" name="bar">
<input type="text" name="in"/>
<input type="text" name="in"/>
<input type="submit" value="Submit"/>
</form></html></body>`
func SimpleServer(w http.ResponseWriter, request *http.Request) {
n, err := io.WriteString(w, "<h1>hello, world</h1>")
if err != nil{
fmt.Println(n)
}
}
func FormServer(w http.ResponseWriter, request *http.Request) {
w.Header().Set("Content-Type", "text/html")
switch request.Method {
case "GET":
io.WriteString(w, form)
case "POST":
request.ParseForm()
io.WriteString(w, request.Form["in"][0])
io.WriteString(w, "\nss")
io.WriteString(w, request.FormValue("in"))
}
}
func Test(w http.ResponseWriter, r *http.Request){
fmt.Println("handler hello")
n, err := fmt.Fprintf(w, "hello world!")
fmt.Println(n)
if err != nil{
fmt.Println("write error:", n)
}
}
func main() {
http.HandleFunc("/", Test)
http.HandleFunc("/test1", SimpleServer)
http.HandleFunc("/test2", FormServer)
if err := http.ListenAndServe("127.0.0.1:80", nil); err != nil {
fmt.Println("http listen eror")
}
}
以上是关于go 表单的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot中表单提交报错“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“(代码片段
npm : 无法加载文件 D:softcodeProcess ode ode_global pm.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.micr +(代码片段