Use http.Post from the standard library to send a POST request with JSON data.
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
data := map[string]string{"key": "value"}
jsonData, _ := json.Marshal(data)
resp, err := http.Post("https://api.example.com/endpoint", "application/json", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
fmt.Println("Status:", resp.Status)
}