update
This commit is contained in:
parent
54d6175318
commit
5ae2274baa
1 changed files with 14 additions and 3 deletions
17
go/l19/l2.go
17
go/l19/l2.go
|
|
@ -19,16 +19,27 @@ func main() {
|
|||
user := UserStruct{
|
||||
Age: 66,
|
||||
Name: "Sergey",
|
||||
Email: "Likhodeev.60@mail.ru"
|
||||
Email: "Likhodeev.60@mail.ru",
|
||||
}
|
||||
JsonData, err := json.Marshal(user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := &http.Client(
|
||||
client := &http.Client{
|
||||
Timeout: 5 * time.Second,
|
||||
)
|
||||
}
|
||||
req, err := http.NewRequest("POST", "http://127.0.0.1:7777/user", bytes.NewBuffer(JsonData))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("status code %d\n", resp.StatusCode)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
Loading…
Reference in a new issue