在Server端解析HTTP请求的时候,
func ProcScaleOutReq(rsp http.ResponseWriter, req *http.Request) {
req.ParseForm()
//bodyStr := [1024]byte{}
//bodySlc := bodyStr[:]
var bodySlc []byte = make([]byte, 1024)
bodyLen,readErr := req.Body.Read(bodySlc)
if readErr == nil {
fmt.Println("read body error")
}else{
fmt.Println("the body has ",bodyLen," bytes")
}
fmt.Println("the body is:", string(bodySlc))
fmt.Println("the len of body ", len(bodySlc))
fmt.Fprintln(rsp, "hello" + req.URL.String())
//var str := string(bodySlc) 这里直接使用Read方法读出来的byte[],str中会有多余的空格。
str := byteString(bodySlc)
fmt.Println("the length of str is ", len(str))
var body2 ReqBody
err := json.Unmarshal([]byte(str), &body2)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("name:" + body2.Name)
fmt.Println("name:" + body2.Body)
fmt.Println("name:" + body2.Time)
}
}