diff --git a/edge/report/report.go b/edge/report/report.go index 39e0278..fb54829 100644 --- a/edge/report/report.go +++ b/edge/report/report.go @@ -23,7 +23,7 @@ func Online(prov, city, isp string) (id int32, host string, err error) { ispInt = 3 } - body, err := json.Marshal(map[string]any{ + bytes, err := json.Marshal(map[string]any{ "prov": prov, "city": city, "isp": ispInt, @@ -33,14 +33,9 @@ func Online(prov, city, isp string) (id int32, host string, err error) { if err != nil { return 0, "", err } + var body = strings.NewReader(string(bytes)) - req, err := http.NewRequest("POST", env.EndpointOnline, strings.NewReader(string(body))) - if err != nil { - return 0, "", fmt.Errorf("创建请求失败: %w", err) - } - - req.Header.Set("Content-Type", "application/json") - resp, err := http.DefaultClient.Do(req) + resp, err := http.Post(env.EndpointOnline, "application/json", body) if err != nil { return 0, "", fmt.Errorf("执行请求失败: %w", err) } @@ -49,7 +44,7 @@ func Online(prov, city, isp string) (id int32, host string, err error) { return 0, "", errors.New("状态码: " + resp.Status) } - bytes, err := io.ReadAll(resp.Body) + bytes, err = io.ReadAll(resp.Body) if err != nil { return 0, "", fmt.Errorf("读取响应失败: %w", err) } @@ -77,12 +72,7 @@ func Offline() error { } var body = strings.NewReader(string(bytes)) - req, err := http.NewRequest("POST", env.EndpointOffline, body) - if err != nil { - return fmt.Errorf("创建请求失败: %w", err) - } - - resp, err := http.DefaultClient.Do(req) + resp, err := http.Post(env.EndpointOffline, "application/json", body) if err != nil { return fmt.Errorf("执行请求失败: %w", err) }