mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
32 lines
698 B
Go
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")
|
|
}
|
|
}
|