diff --git a/models/PrepareRequest.go b/models/PrepareRequest.go index 1b264a4..b88b93e 100644 --- a/models/PrepareRequest.go +++ b/models/PrepareRequest.go @@ -3,7 +3,6 @@ package models import ( "bytes" "encoding/base64" - jsonp "encoding/json" "errors" "fmt" "github.com/wangluozhe/fhttp" @@ -139,7 +138,7 @@ func (pr *PrepareRequest) Prepare_body(data *url.Values, files *url.Files, json } if data == nil && json != nil { content_type = "application/json" - json_byte, err := jsonp.Marshal(json) + json_byte, err := utils.Marshal(json) if err != nil { return err } diff --git a/utils/code.go b/utils/code.go index 3fb01c2..76a8832 100644 --- a/utils/code.go +++ b/utils/code.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "encoding/binary" "encoding/hex" + "encoding/json" "errors" "net/url" "regexp" @@ -179,3 +180,17 @@ func UnEscape(s interface{}) string { str = DecodeURIComponent(str) return str } + +// Marshal 避免json.Marshal对 "<", ">", "&" 等字符进行HTML编码 +func Marshal(data interface{}) ([]byte, error) { + var buffer bytes.Buffer + + encoder := json.NewEncoder(&buffer) + + // 禁用HTML转义 + encoder.SetEscapeHTML(false) + + err := encoder.Encode(data) + + return buffer.Bytes(), err +}