From c703f7b6e16dadb59be6a79b99e6da948d497c13 Mon Sep 17 00:00:00 2001 From: athul Date: Fri, 24 Jan 2020 13:39:14 +0530 Subject: [PATCH] Added Support for Token and Basic Requests --- methods/post.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/methods/post.go b/methods/post.go index 3ab8028..acdfa1a 100644 --- a/methods/post.go +++ b/methods/post.go @@ -13,9 +13,18 @@ func Postbasic(c *cli.Context) { url := c.String("url") var jsonStr = []byte(c.String("body")) req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) - req.Header.Set("X-Custom-Header", "myvalue") + //req.Header.Set("X-Custom-Header", "myvalue") req.Header.Set("Content-Type", c.String("ctype")) - + if c.String("token") != "" { + var bearer = "Bearer " + c.String("token") + req.Header.Add("Authorization", bearer) + } + if c.String("u") != "" && c.String("p") != "" { + un := c.String("u") + pw := c.String("p") + req.Header.Add("Authorization", "Basic "+basicAuth(un, pw)) + } + fmt.Print(req.Header) client := &http.Client{} resp, err := client.Do(req) if err != nil {