From 37d4bb3df50577f81e6048ec09d5fefe7a2842c7 Mon Sep 17 00:00:00 2001 From: Hu Risheng Date: Thu, 5 Oct 2017 14:34:52 -0500 Subject: [PATCH] add XMLBody method for httplib --- httplib/httplib.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/httplib/httplib.go b/httplib/httplib.go index 4fd572d6..5d82ab33 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -317,7 +317,19 @@ func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest { } return b } - +// XMLBody adds request raw body encoding by XML. +func (b *BeegoHTTPRequest) XMLBody(obj interface{}) (*BeegoHTTPRequest, error) { + if b.req.Body == nil && obj != nil { + byts, err := xml.Marshal(obj) + if err != nil { + return b, err + } + b.req.Body = ioutil.NopCloser(bytes.NewReader(byts)) + b.req.ContentLength = int64(len(byts)) + b.req.Header.Set("Content-Type", "application/xml") + } + return b, nil +} // JSONBody adds request raw body encoding by JSON. func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error) { if b.req.Body == nil && obj != nil {