Skip to content

Instantly share code, notes, and snippets.

@rockey5520
Created October 4, 2022 15:30
Show Gist options
  • Save rockey5520/ddc07b1492b7d26562974117b6e7f9e0 to your computer and use it in GitHub Desktop.
Save rockey5520/ddc07b1492b7d26562974117b6e7f9e0 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
)
func main() {
reqBody, err := json.Marshal(map[string]string{
"username": "admin",
"password": "admin",
})
if err != nil {
log.Fatal(err)
}
resp, err := http.Post("https://httpbin.org/post", "application/json", bytes.NewBuffer(reqBody))
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
fmt.Println("Response status:", resp.Status)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
log.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment