1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 12:52:27 +08:00

json marshal改为encode ,不转义html字符(例如:&) #15

This commit is contained in:
silenceper
2017-02-13 00:25:14 +08:00
parent 7f04a03b18
commit 7c4b8fe172

View File

@@ -27,12 +27,16 @@ func HTTPGet(uri string) ([]byte, error) {
//PostJSON post json 数据请求
func PostJSON(uri string, obj interface{}) ([]byte, error) {
jsonData, err := json.Marshal(obj)
jsonBuf := new(bytes.Buffer)
enc := json.NewEncoder(jsonBuf)
enc.SetEscapeHTML(false)
err := enc.Encode(obj)
if err != nil {
return nil, err
}
body := bytes.NewBuffer(jsonData)
response, err := http.Post(uri, "application/json;charset=utf-8", body)
response, err := http.Post(uri, "application/json;charset=utf-8", jsonBuf)
if err != nil {
return nil, err
}