目录
一. 请求
1.1 请求首部
func header(w http.ResponseWriter, r *http.request){
h := r.Header
h := r.Header["Accept-Encoding"]
}
1.2 请求主体
func body(w http.ResponseWriter, r *http.request){
len := r.ConTenLength
body := make(]byte, len)
r.Body.Read(body)
h := r.Header
h := r.Header["Accept-Encoding"]
}
1.3 go 与html 表单 content-type
application/x-www-form-urlencoded
name=zhx&age=13
通过&来连接
简单的文本数据用这个
multipart/form/-data
大量数据用这个比如 文件上传
text/plain
1.3.1 From字段
会获取到url传递参数还有表单传递参数
r.ParseFrom
r.From
1.3.2 PostFrom字段
假如既有url传递参数还有表单传递参数 那么使用PostFrom获取表单传递过来的参数
注意只能用这个content-type = application/x-www-form-urlencoded
1.3.3 MultipartFrom 字段
可以处理 multipart/form/-data
的结构
1.3.4 FormValue
可以不用手动调用r.ParseFrom
函数和ParseMultipartForm
函数
但是不适用于content-type = multipart/form/-data
1.4 总结
二. 响应
2.1 服务器返回json
type Post strucct{
User string
Threads[] string
}