funcparsePostForm(r *Request)(vs url.Values, err error){if r.Body ==nil{
err = errors.New("missing form body")return}
ct := r.Header.Get("Content-Type")// RFC 7231, section 3.1.1.5 - empty type// MAY be treated as application/octet-streamif ct ==""{
ct ="application/octet-stream"}
ct,_, err = mime.ParseMediaType(ct)switch{case ct =="application/x-www-form-urlencoded":var reader io.Reader = r.Body
maxFormSize :=int64(1<<63-1)if_, ok := r.Body.(*maxBytesReader);!ok {
maxFormSize =int64(10<<20)// 10 MB is a lot of text.
reader = io.LimitReader(r.Body, maxFormSize+1)}
b, e := io.ReadAll(reader)if e !=nil{if err ==nil{
err = e
}break}ifint64(len(b))> maxFormSize {
err = errors.New("http: POST too large")return}
vs, e = url.ParseQuery(string(b))if err ==nil{
err = e
}case ct =="multipart/form-data":// handled by ParseMultipartForm (which is calling us, or should be)// TODO(bradfitz): there are too many possible// orders to call too many functions here.// Clean this up and write more tests.// request_test.go contains the start of this,// in TestParseMultipartFormOrder and others.}return}
这种追源码就清楚了,PostForm只在下面这里赋值
查看这部分代码,PostForm只在header为 "application/x-www-form-urlencoded" 时解析body内容。
因此:PostFormValue(key) 只在上述情况起作用
看了源码:FormValue(key),貌似也会包含PostFormValue的内容。
go都是开源的,有啥不清楚的,看看源码呗,比到处问人快多了。