go make http post request code example
Example: go make http post request
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
func main() {
//Encode the data
postBody, _ := json.Marshal(map[string]string{
"name": "Toby",
"email": "[email protected]",
})
responseBody := bytes.NewBuffer(postBody)
//Leverage Go's HTTP Post function to make request
resp, err := http.Post("https://postman-echo.com/post", "application/json", responseBody)
}