mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
fix 恢复直接使用enc.SetEscapeHTML参数 (#412)
Co-authored-by: zhenlinwen <zhenlinwen@tencent.com>
This commit is contained in:
23
util/http.go
23
util/http.go
@@ -48,15 +48,14 @@ func HTTPPost(uri string, data 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
|
||||||
}
|
}
|
||||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003c"), []byte("<"))
|
response, err := http.Post(uri, "application/json;charset=utf-8", jsonBuf)
|
||||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003e"), []byte(">"))
|
|
||||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u0026"), []byte("&"))
|
|
||||||
body := bytes.NewBuffer(jsonData)
|
|
||||||
response, err := http.Post(uri, "application/json;charset=utf-8", body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -70,17 +69,15 @@ func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
|||||||
|
|
||||||
// PostJSONWithRespContentType post json数据请求,且返回数据类型
|
// PostJSONWithRespContentType post json数据请求,且返回数据类型
|
||||||
func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, error) {
|
func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003c"), []byte("<"))
|
response, err := http.Post(uri, "application/json;charset=utf-8", jsonBuf)
|
||||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003e"), []byte(">"))
|
|
||||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u0026"), []byte("&"))
|
|
||||||
|
|
||||||
body := bytes.NewBuffer(jsonData)
|
|
||||||
response, err := http.Post(uri, "application/json;charset=utf-8", body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user