mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-17 19:22:27 +08:00
json marshal改为encode ,不转义html字符(例如:&) #15
This commit is contained in:
10
util/http.go
10
util/http.go
@@ -27,12 +27,16 @@ func HTTPGet(uri string) ([]byte, error) {
|
|||||||
|
|
||||||
//PostJSON post json 数据请求
|
//PostJSON post json 数据请求
|
||||||
func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user