1. package main
    2. import (
    3. "bytes"
    4. "encoding/json"
    5. "fmt"
    6. "io/ioutil"
    7. "net/http"
    8. )
    9. const url = "http://xxxxxxxxxxxxxxxxxx"
    10. func postData() bool {
    11. data := make(map[string]string)
    12. data["username"] = "hequan"
    13. data["password"] = "password"
    14. b, _ := json.Marshal(data)
    15. resp, err := http.Post(url,
    16. "application/json",
    17. bytes.NewBuffer(b))
    18. if err != nil {
    19. fmt.Println(err)
    20. }
    21. defer resp.Body.Close()
    22. body, _ := ioutil.ReadAll(resp.Body)
    23. fmt.Println(string(body))
    24. return true
    25. }
    26. func main() {
    27. postData()
    28. }