From 14a778101d091e96e98c444c5016f4818592ac59 Mon Sep 17 00:00:00 2001 From: luorijun Date: Sat, 17 May 2025 11:12:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=20HTTP=20=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91=EF=BC=9B=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E8=AF=B7=E6=B1=82=E5=A4=B1=E8=B4=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- edge/report/report.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) 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) }