下面是一个用围棋写的服务器.

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)
}

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

推荐答案

这样地:

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)
}

Go相关问答推荐

如何从google.golang.org/grpc/stats包中将golang中不同事件的输出进行组合,以获取func HandlePRC

更改位置级别和时间戳零点Golang

如何使用中间件更改http请求的响应代码?

这是实现超时的常见方法,为什么 time.After 不起作用

无法使用带有 422 的 go-github 创建提交 - 更新不是快进

你如何在 Golang 代码中测试 filepath.Abs​​ 失败?

致命错误 - 所有 Goroutines 都睡着了!僵局

具有嵌套重复的正则表达式

Golang 通过接口反映/迭代{}

如何仅提取时间作为持续时间

为超时的单元测试创​​建 deadlineExceededError:true

grpc-gateway:重定向与定义不匹配(原始文件)

致命错误:找不到由 zergon321/reisen 引起的libavcodec/avcodec.h文件

从 Makefile 运行时权限被拒绝

当有多个同名包时如何在vscode中显示golang包完整路径?

函数调用中的类型参数panic

从另一个没有重复的确定性 int

gob 解码器仅返回数组中的第一个元素

在 go (1.18) 的泛型上实现多态的最佳方法是什么?

如何动态解析 Go Fiber 中的请求正文?