下面是用go编写的服务器。

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
    fmt.Fprintf(w,"%s",r.Method)
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

如何提取发送到POST URL的localhost:8080/something数据?

最佳答案

像这样:

func handler(w http.ResponseWriter, r *http.Request) {
    r.ParseForm()                     // Parses the request body
    x := r.Form.Get("parameter_name") // x will be "" if parameter is not set
    fmt.Println(x)
}

关于http - 如何在go服务器中提取post参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16512009/

10-11 22:30
查看更多