Files
curlx/curlx_test.go
T

63 lines
1.3 KiB
Go
Raw Normal View History

2023-11-08 09:47:27 +08:00
package curlx
import (
"context"
2025-09-13 22:20:06 +08:00
"encoding/json"
2023-11-08 09:47:27 +08:00
"fmt"
"io"
2025-09-13 22:20:06 +08:00
"net/http"
2023-11-08 09:47:27 +08:00
"os"
"testing"
)
2023-11-24 22:19:59 +08:00
func TestGet(t *testing.T) {
2025-12-28 15:14:05 +08:00
resp, 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
)
2025-12-28 15:14:05 +08:00
t.Log(string(resp), err)
2023-11-08 09:51:25 +08:00
}
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
},
}
2025-09-13 22:20:06 +08:00
by, _ := json.Marshal(s)
2024-01-01 14:10:18 +08:00
p := ClientParams{
2025-12-28 15:14:05 +08:00
Url: "http://tech-dev.sealmoo.com/api/material/upload",
Method: "POST",
Body: by,
Headers: http.Header{
"Content-Type": []string{"application/json"},
2025-09-13 22:20:06 +08:00
"Authorization": []string{"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOjAsImNsaWVudF9pZCI6MCwidXNlcl9pZCI6MSwiZXhwIjoxNzAxMzk3NzkxfQ.9_uJ6y8I4JZTwgSenwHC_01nddLuI4zmgpyPhn5M6j8"},
2023-11-08 09:47:27 +08:00
},
2023-11-24 22:19:59 +08:00
ContentType: ContentTypeForm,
2023-11-08 09:47:27 +08:00
}
2025-12-28 15:14:05 +08:00
resp, err := NewCurlx().Send(context.Background(), SetParamsAll(p))
fmt.Println(resp, err)
2023-11-08 09:47:27 +08:00
}
2024-12-12 10:16:15 +08:00
func TestProxy(t *testing.T) {
c := NewCurlx()
c.WithProxySocks5("127.0.0.1:1080")
2025-12-28 15:14:05 +08:00
res, err := c.Send(context.Background(), SetParamsUrl("https://www.google.com"), SetParamsMethod(MethodGet))
t.Log(string(res), err)
2024-12-12 10:16:15 +08:00
}