func ProtoWrite() {
p1 := &behavior.Picture{
Filename: "kk",
Relpath: "d:/1024",
Clicks: 100,
}
ps := &behavior.Pictures{
Pic: p1,
}
data, err := proto.Marshal(ps)
if err != nil {
log.Fatalf("ProtoBuf 数据编码失败->%v\n", err.Error())
}
contentType := "application/json;charset=utf-8"
url := "http://192.168.100.101:8081/index/index"
body := bytes.NewBuffer(data)
res, err := http.Post(url, contentType, body)
if err != nil {
log.Panic("http post failed")
}
result, err := ioutil.ReadAll(res.Body)
res.Body.Close()
log.Println(result) log.Println(string(result))
}