|
@@ -58,6 +58,36 @@ func HttpPostJsonResponseString(url string, params map[string]string) (string, e
|
|
|
return string(body), nil
|
|
|
}
|
|
|
|
|
|
+func HttpPostWithHeaders(baseUrl string, headers map[string]string, params map[string]string) (string, error) {
|
|
|
+ // 构建请求体
|
|
|
+ data := url.Values{}
|
|
|
+ for key, value := range params {
|
|
|
+ data.Set(key, value)
|
|
|
+ }
|
|
|
+ requestBody := bytes.NewBufferString(data.Encode())
|
|
|
+
|
|
|
+ // 创建请求
|
|
|
+ req, err := http.NewRequest("POST", baseUrl, requestBody)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置请求头
|
|
|
+ for key, value := range headers {
|
|
|
+ req.Header.Set(key, value)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送请求
|
|
|
+ client := &http.Client{}
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ body, err := io.ReadAll(resp.Body)
|
|
|
+
|
|
|
+ return string(body), nil
|
|
|
+}
|
|
|
+
|
|
|
func HttpGetStringAddHeadersResponseString(baseUrl string, headers map[string]string, params map[string]string) (string, error) {
|
|
|
|
|
|
// 将参数编码到URL中
|