猜你喜欢
- Go语言的Json管理模式
- golang json string remove field
- [笔记] Golang JSON
- go: json解析库go-simplejson使用
- Golang 1.6: 数据库NULL值遇到JSON和模板(Template)
- beego下ie提示下载json
- golang中json编码和解码
- com.google.gson.JsonArray 转换成list
- Go中的JSON
一、提交json
参考:http://stackoverflow.com/a/24455606
func main() {
url := "http://restapi3.apiary.io/notes"
fmt.Println("URL:>", url)
var jsonStr = []byte(`{"title":"Buy cheese and bread for breakfast."}`)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}
二、获取并解析json
待续