Compare commits

..

2 Commits

Author SHA1 Message Date
cd72620e49 add HttpPostJSON 2025-05-23 10:45:28 +08:00
zhaoxiaorong
5bb23deb3b fix 2025-05-21 20:13:55 +08:00
2 changed files with 11 additions and 0 deletions

View File

@@ -15,4 +15,5 @@ var (
Type_Delete string = "delete" Type_Delete string = "delete"
Type_Query string = "query" Type_Query string = "query"
Type_Other string = "other" Type_Other string = "other"
Type_Create string = "create"
) )

View File

@@ -2,6 +2,7 @@ package utils
import ( import (
"bytes" "bytes"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@@ -121,6 +122,15 @@ func HttpGet(url string) ([]byte, error) {
return body, err return body, err
} }
func HttpPostJSON(url string, header map[string]string, data map[string]any) ([]byte, error) {
bytes, err := json.Marshal(data)
if err != nil {
return nil, err
}
return HttpPost(url, header, bytes)
}
func HttpPost(url string, header map[string]string, data []byte) ([]byte, error) { func HttpPost(url string, header map[string]string, data []byte) ([]byte, error) {
var err error var err error
reader := bytes.NewBuffer(data) reader := bytes.NewBuffer(data)