|
|
@ -1,20 +1,24 @@ |
|
|
|
package utils |
|
|
|
|
|
|
|
import ( |
|
|
|
"LAPP_GAAS_GFrame_BACKEND/conf" |
|
|
|
"bytes" |
|
|
|
"io" |
|
|
|
"io/ioutil" |
|
|
|
"mime/multipart" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"os" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
func GetRequest(url string, headers map[string]string) (body []byte, err error) { |
|
|
|
func GetRequest(u string, headers map[string]string) (body []byte, err error) { |
|
|
|
proxy := func(_ *http.Request) (*url.URL, error) { |
|
|
|
return url.Parse(conf.DbConfig.Proxy) |
|
|
|
} |
|
|
|
|
|
|
|
// 超时时间:5秒
|
|
|
|
client := &http.Client{Timeout: 5 * time.Second} |
|
|
|
req, err := http.NewRequest(http.MethodGet, url, nil) |
|
|
|
transport := &http.Transport{Proxy: proxy} |
|
|
|
client := &http.Client{Transport: transport} |
|
|
|
req, err := http.NewRequest(http.MethodGet, u, nil) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
@ -34,8 +38,12 @@ func GetRequest(url string, headers map[string]string) (body []byte, err error) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func PostFormDataWithSingleFile(url string, filepath string, filename string, headers map[string]string) (body []byte, err error){ |
|
|
|
client := http.Client{} |
|
|
|
func PostFormDataWithSingleFile(u string, filepath string, filename string, headers map[string]string) (body []byte, err error){ |
|
|
|
proxy := func(_ *http.Request) (*url.URL, error) { |
|
|
|
return url.Parse(conf.DbConfig.Proxy) |
|
|
|
} |
|
|
|
transport := &http.Transport{Proxy: proxy} |
|
|
|
client := &http.Client{Transport: transport} |
|
|
|
bodyBuf := &bytes.Buffer{} |
|
|
|
bodyWrite := multipart.NewWriter(bodyBuf) |
|
|
|
file, err := os.Open(filepath) |
|
|
@ -59,7 +67,7 @@ func PostFormDataWithSingleFile(url string, filepath string, filename string, he |
|
|
|
} |
|
|
|
// 创建请求
|
|
|
|
contentType := bodyWrite.FormDataContentType() |
|
|
|
req, err := http.NewRequest(http.MethodPost, url, bodyBuf) |
|
|
|
req, err := http.NewRequest(http.MethodPost, u, bodyBuf) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|