Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

my_post_config_meta_test.go 752B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "fmt"
  4. "io"
  5. "log"
  6. "net/http"
  7. "testing"
  8. )
  9. func TestConfigMeta(t *testing.T) {
  10. httpClient := &http.Client{}
  11. url := "http://localhost:8080/api/init/config/meta"
  12. req, err := http.NewRequest("POST", url, nil)
  13. if err != nil {
  14. log.Printf("NewRequest:%v", err)
  15. }
  16. req.Header.Set("Authorization", "Bearer 123")
  17. req.Header.Set("Content-Type", "application/json")
  18. resp, err := httpClient.Do(req)
  19. if err != nil {
  20. fmt.Printf("发送请求失败: %v\n", err)
  21. return
  22. }
  23. defer resp.Body.Close()
  24. // 读取响应
  25. body, err := io.ReadAll(resp.Body)
  26. if err != nil {
  27. fmt.Printf("读取响应失败: %v\n", err)
  28. return
  29. }
  30. fmt.Printf("状态码: %d\n", resp.StatusCode)
  31. fmt.Printf("响应体: %s\n", string(body))
  32. }