package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
)
type LoginRequest struct {
Account string `json:"account"`
Password string `json:"password"`
}
func main() {
reqBody := LoginRequest{
Account: "admin",
Password: "123456",
}
data, err := json.Marshal(reqBody)
if err != nil {
fmt.Println(err)
return
}
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Post(
"http://127.0.0.1:8080/login",
"application/json",
bytes.NewReader(data),
)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp.StatusCode)
fmt.Println(string(body))
}