mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: 下载eapi文件,并添加token
This commit is contained in:
@@ -520,7 +520,19 @@ func DownloadFile(filePath string, url string) error {
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
resp, err := http.Get(url)
|
||||
// 创建一个新的 HTTP 请求
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 添加自定义头部
|
||||
req.Header.Add("accessKey", "ies.vedem.video")
|
||||
req.Header.Add("token", "***REMOVED***")
|
||||
|
||||
// 创建一个 HTTP 客户端并发送请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -530,6 +542,7 @@ func DownloadFile(filePath string, url string) error {
|
||||
return fmt.Errorf("bad status: %s, download failed", resp.Status)
|
||||
}
|
||||
|
||||
// 将响应主体写入文件
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
12
hrp/internal/builtin/utils_test.go
Normal file
12
hrp/internal/builtin/utils_test.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDownload(t *testing.T) {
|
||||
err := DownloadFile("/tmp/bytedance.ds.zip", "https://gtf-eapi-cn.bytedance.com/cn/mostRecent/bytedance.ds.zip")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user