add HttpPostJSON

This commit is contained in:
yanweidong 2025-05-23 10:45:28 +08:00
parent 5bb23deb3b
commit cd72620e49
1 changed files with 10 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package utils
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
@ -121,6 +122,15 @@ func HttpGet(url string) ([]byte, error) {
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) {
var err error
reader := bytes.NewBuffer(data)