|
|
|
@ -26,6 +26,14 @@ func (the *HttpHelper) Initial() { |
|
|
|
the.client.Timeout = time.Minute |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (the *HttpHelper) InitialWithTls() { |
|
|
|
the.client = http.Client{} |
|
|
|
//取消证书校验,避免证书过期问题
|
|
|
|
the.client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} |
|
|
|
the.client.Timeout = time.Minute |
|
|
|
} |
|
|
|
|
|
|
|
func (the *HttpHelper) HttpGet(queryBody string) string { |
|
|
|
url := the.Url |
|
|
|
client := the.client |
|
|
|
@ -40,6 +48,34 @@ func (the *HttpHelper) HttpGet(queryBody string) string { |
|
|
|
body, err := io.ReadAll(resp.Body) |
|
|
|
return string(body) |
|
|
|
} |
|
|
|
func (the *HttpHelper) HttpGetWithHeaderWithTLS(queryBody string, headerMap map[string]string) string { |
|
|
|
url := the.Url |
|
|
|
client := the.client |
|
|
|
req, err := http.NewRequest("GET", url, strings.NewReader(queryBody)) |
|
|
|
req.Header.Set("Content-Type", "application/json") |
|
|
|
|
|
|
|
for k, v := range headerMap { |
|
|
|
req.Header.Set(k, v) |
|
|
|
} |
|
|
|
|
|
|
|
resp, err := client.Do(req) |
|
|
|
if err != nil { |
|
|
|
log.Printf("查询esproxy 异常=>%s", err.Error()) |
|
|
|
return "" |
|
|
|
} |
|
|
|
defer func(resp *http.Response) { |
|
|
|
if resp != nil && resp.Body != nil { |
|
|
|
errClose := resp.Body.Close() |
|
|
|
if errClose != nil { |
|
|
|
log.Printf("关闭异常") |
|
|
|
} |
|
|
|
} |
|
|
|
}(resp) |
|
|
|
log.Println("http get 请求,url", url, " <- code=", resp.StatusCode) |
|
|
|
body, err := io.ReadAll(resp.Body) |
|
|
|
return string(body) |
|
|
|
} |
|
|
|
|
|
|
|
func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string]string) string { |
|
|
|
url := the.Url |
|
|
|
client := the.client |
|
|
|
@ -49,6 +85,7 @@ func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string] |
|
|
|
for k, v := range headerMap { |
|
|
|
req.Header.Set(k, v) |
|
|
|
} |
|
|
|
|
|
|
|
//取消证书校验,避免证书过期问题
|
|
|
|
client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} |
|
|
|
|
|
|
|
@ -69,6 +106,7 @@ func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string] |
|
|
|
body, err := io.ReadAll(resp.Body) |
|
|
|
return string(body) |
|
|
|
} |
|
|
|
|
|
|
|
func (the *HttpHelper) Publish(messageBytes []byte) (string, error) { |
|
|
|
url := the.Url |
|
|
|
client := the.client |
|
|
|
|