This commit is contained in:
jiangyong 2026-06-25 00:33:27 +08:00
parent 1cdf6cb507
commit b8858451cb
1 changed files with 31 additions and 0 deletions

31
http.go
View File

@ -10,6 +10,37 @@ import (
"time"
)
func HttpPut(link string, header map[string]string, json []byte) ([]byte, error) {
client := &http.Client{Timeout: 20 * time.Second}
//忽略https的证书
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
u, _ := url.Parse(link)
req, err := http.NewRequest("PUT", u.String(), bytes.NewBuffer(json))
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", "application/json")
if header != nil {
for k, v := range header {
req.Header.Set(k, v)
}
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%d:%s", resp.StatusCode, resp.Status)
}
return io.ReadAll(resp.Body)
}
// PostJson 请求
func HttpPost(link string, header map[string]string, json []byte) ([]byte, error) {
client := &http.Client{Timeout: 20 * time.Second}