diff --git a/_examples/core/http_test.go b/_examples/core/http_test.go index 592a859..b84761b 100644 --- a/_examples/core/http_test.go +++ b/_examples/core/http_test.go @@ -55,7 +55,7 @@ func TestHttpProxyPostFull(t *testing.T) { func TestHttpProxyBasic(t *testing.T) { fmt.Println(httpKit.HttpProxyBasic("https://cip.cc", http.MethodGet, nil, nil, "", 300, "http", - "", "", "255.255.255.255:52724")) + "", "", "255.255.255.255:29093")) } func TestUA(t *testing.T) { diff --git a/core/httpKit/httpClientKit.go b/core/httpKit/httpClientKit.go index 601296d..3f2815f 100644 --- a/core/httpKit/httpClientKit.go +++ b/core/httpKit/httpClientKit.go @@ -142,6 +142,10 @@ func HttpBasic(urlString, httpMethod string, headers, paramMap map[string]string } bodyReader := strings.NewReader(body) req, _ := http.NewRequest(httpMethod, urlString, bodyReader) + if headers == nil { + // 如果headers为空,初始化 + headers = make(map[string]string, 0) + } for k, v := range headers { req.Header.Add(k, v) } @@ -275,6 +279,10 @@ func HttpProxyBasic(urlStr, httpMethod string, headers, paramMap map[string]stri return headers, "", err } // 获取新的headers数据 + if headers == nil { + // 如果headers为空,初始化 + headers = make(map[string]string, 0) + } for k, v := range res.Header { headers[k] = v[0] }