Skip to content

Instantly share code, notes, and snippets.

@itwars
Created March 9, 2018 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itwars/2fc9636a5cccd423ca66271f22ad5c19 to your computer and use it in GitHub Desktop.
Save itwars/2fc9636a5cccd423ca66271f22ad5c19 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "http://mockbin.com/request?foo=bar&foo=baz"
payload := strings.NewReader("{\"foo\": \"bar\"}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("cookie", "foo=bar; bar=baz")
req.Header.Add("accept", "application/json")
req.Header.Add("content-type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment