Created
October 4, 2022 15:30
-
-
Save rockey5520/ddc07b1492b7d26562974117b6e7f9e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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