package request import ( "bytes" "errors" "io" "net/http" ) func post(url string, contentType string, body []byte) ([]byte, error) { resp, e1 := http.Post(url, contentType, bytes.NewReader(body)) if e1 != nil { return nil, e1 } if resp.StatusCode > 299 { return nil, errors.New(resp.Status) } body, e2 := io.ReadAll(resp.Body) resp.Body.Close() if e2 != nil { return nil, e2 } return body, nil } // PostJSON 使用 POST 方式发送 json 数据 func PostJSON(url string, body []byte) ([]byte, error) { return post(url, ContentTypeJSON, body) }