2023-11-08 09:47:27 +08:00
|
|
|
package curlx
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2023-11-24 22:19:59 +08:00
|
|
|
func TestGet(t *testing.T) {
|
2024-01-01 14:10:18 +08:00
|
|
|
resp, code, err := NewCurlx().Send(context.Background(),
|
2024-01-12 21:06:13 +08:00
|
|
|
SetParamsUrl("https://www.baidu.com"),
|
|
|
|
|
SetParamsMethod(MethodGet),
|
2024-01-01 14:10:18 +08:00
|
|
|
)
|
2023-11-08 09:51:25 +08:00
|
|
|
t.Log(resp, code, err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 22:19:59 +08:00
|
|
|
func TestForm(t *testing.T) {
|
2023-11-08 09:47:27 +08:00
|
|
|
|
|
|
|
|
file, err := os.Open("./go.mod")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
|
|
b, _ := io.ReadAll(file)
|
|
|
|
|
|
2023-11-24 22:19:59 +08:00
|
|
|
s := []FormParam{
|
2023-11-08 09:47:27 +08:00
|
|
|
{
|
2023-11-24 22:19:59 +08:00
|
|
|
FieldName: "file",
|
|
|
|
|
FileName: file.Name(),
|
|
|
|
|
FieldType: "file",
|
|
|
|
|
FileBytes: b,
|
2023-11-08 09:47:27 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-01 14:10:18 +08:00
|
|
|
p := ClientParams{
|
2023-11-08 09:47:27 +08:00
|
|
|
Url: "http://tech-dev.sealmoo.com/api/material/upload",
|
|
|
|
|
Method: "POST",
|
2024-01-12 21:06:13 +08:00
|
|
|
Body: s,
|
2023-11-08 09:47:27 +08:00
|
|
|
Headers: map[string]interface{}{
|
|
|
|
|
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOjAsImNsaWVudF9pZCI6MCwidXNlcl9pZCI6MSwiZXhwIjoxNzAxMzk3NzkxfQ.9_uJ6y8I4JZTwgSenwHC_01nddLuI4zmgpyPhn5M6j8",
|
|
|
|
|
},
|
2023-11-24 22:19:59 +08:00
|
|
|
ContentType: ContentTypeForm,
|
2023-11-08 09:47:27 +08:00
|
|
|
}
|
2024-01-12 21:06:13 +08:00
|
|
|
resp, code, err := NewCurlx().Send(context.Background(), SetParamsAll(p))
|
2023-11-08 09:47:27 +08:00
|
|
|
fmt.Println(resp, code, err)
|
|
|
|
|
}
|