From 5e2384e95a61b9e7240ec05db510af89f4e64d39 Mon Sep 17 00:00:00 2001 From: aolu Date: Tue, 8 Mar 2016 17:04:14 +0800 Subject: [PATCH] fix json extra newline --- httplib/httplib.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/httplib/httplib.go b/httplib/httplib.go index fb64a30a..76984122 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -301,13 +301,12 @@ func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest { // JSONBody adds request raw body encoding by JSON. func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error) { if b.req.Body == nil && obj != nil { - buf := bytes.NewBuffer(nil) - enc := json.NewEncoder(buf) - if err := enc.Encode(obj); err != nil { + byts, err := json.Marshal(obj) + if err != nil { return b, err } - b.req.Body = ioutil.NopCloser(buf) - b.req.ContentLength = int64(buf.Len()) + b.req.Body = ioutil.NopCloser(bytes.NewReader(byts)) + b.req.ContentLength = int64(len(byts)) b.req.Header.Set("Content-Type", "application/json") } return b, nil