Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
Added Support for Token and Basic Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
athul committed Jan 24, 2020
1 parent 0ed715e commit c703f7b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions methods/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c703f7b

Please sign in to comment.