goでpostするformを作成しています。その中で、htmlは表示されるのですが、送信した後の処理がうまく行きません。どのように変更すれば、良いかわからないので、よろしくお願いします。ソースが綺麗ではないのですが、初めて使う言語なので、よろしくお願いします。
server.go
package main import ( "fmt" "io/ioutil" "net/http" "html/template" ) func process(w http.ResponseWriter, r *http.Request) { r.ParseMultipartForm(1024) fileHeader := r.MultipartForm.File["uploaded"][0] file, err := fileHeader.Open() if err == nil { data, err := ioutil.ReadAll(file) if err == nil { fmt.Fprintln(w, string(data)) } else { http.Error(w, err.Error(), http.StatusInternalServerError) return } } } func client(w http.ResponseWriter, r *http.Request) { err := template.ParseFiles("client.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } } func main() { server := http.Server{ Addr: "127.0.0.1:9000", } http.HandleFunc("/process", process) http.HandleFunc("/client", client) server.ListenAndServe() }
client.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Go Web Programming</title> </head> <body> <form action="http://localhost:9000/process?hello=world&thread=123" method="post" enctype="multipart/form-data"> <input type="text" name="hello" value="sau sheong"/> <input type="text" name="post" value="456"/> <input type="file" name="uploaded"> <input type="submit"> </form> </body> </html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/13 21:52