858d3c14cdedbc5f9135626610aa1ad9a8965b66.svn-base 923 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. )
  8. func main(){
  9. client := &http.Client{}
  10. body := bytes.NewBuffer([]byte("{\"username\":\"00028\",\"password\":\"123456\"}"))
  11. req, err := http.NewRequest("POST",
  12. "https://kptyun.cn:8082/auth",
  13. body,
  14. )
  15. req.Header.Set("Content-Type", "application/json;charset=utf-8")
  16. if err != nil {
  17. // handle error
  18. }
  19. resp, err := client.Do(req)
  20. if err != nil {
  21. fmt.Println(err)
  22. return
  23. }
  24. defer resp.Body.Close()
  25. result_body, err := ioutil.ReadAll(resp.Body)
  26. if err != nil {
  27. fmt.Println(err)
  28. return
  29. }
  30. fmt.Println(string(result_body))
  31. //resp1, err :=http.Post("https://kptyun.cn:8082/auth", "application/x-www-form-urlencoded",nil)
  32. //
  33. //
  34. //
  35. //if err != nil {
  36. // fmt.Println(err)
  37. //}
  38. //
  39. //defer resp1.Body.Close()
  40. //body1, err := ioutil.ReadAll(resp1.Body)
  41. //if err != nil {
  42. // // handle error
  43. //}
  44. //
  45. //fmt.Println(string(body1))
  46. }