Files
requests/test/request/file_test.go
gospider 45c7a3262f sync
2025-07-11 11:54:33 +08:00

32 lines
698 B
Go

package main
import (
"bytes"
"strings"
"testing"
"github.com/gospider007/requests"
)
func TestSendFileWithReader(t *testing.T) {
resp, err := requests.Post(nil, "https://httpbin.org/anything", requests.RequestOption{
Form: map[string]any{
"file": requests.File{
Content: bytes.NewBuffer([]byte("test")), //support: io.Reader, string, []byte
FileName: "test.txt",
ContentType: "text/plain",
},
},
})
if err != nil {
t.Fatal(err)
}
jsonData, err := resp.Json()
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(jsonData.Get("headers.Content-Type").String(), "multipart/form-data") {
t.Fatal("json data error")
}
}