Skip to content

Instantly share code, notes, and snippets.

@dav1dddd
Created July 28, 2020 14:11
Show Gist options
  • Save dav1dddd/b5134d04d3386f91c8d1842e75fdd76f to your computer and use it in GitHub Desktop.
Save dav1dddd/b5134d04d3386f91c8d1842e75fdd76f to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"net/http"
)
var (
whurl = flag.String("whurl", "", "webhook url")
content = flag.String("content", "", "content")
)
func main() {
flag.Parse()
client := &http.Client{}
jsonstr := []byte(fmt.Sprintf(`{"content": "%v"}`, *content))
request, err := http.NewRequest("POST", *whurl, bytes.NewBuffer(jsonstr))
if err != nil {
panic(err)
}
request.Header.Add("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
// Read body
body, _ := ioutil.ReadAll(response.Body)
fmt.Println(string(body))
fmt.Println(response.Status)
fmt.Println(response.Header)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment