This commit is contained in:
kzkzzzz
2025-09-14 00:19:27 +08:00
parent 866b2cf1ed
commit ea6896cf05
6 changed files with 539 additions and 16 deletions

View File

@@ -0,0 +1,39 @@
package fasthttpc
import (
"context"
"fmt"
"testing"
"time"
)
func TestClient(t *testing.T) {
client := New(WithUseCtxTimeout(true), WithTimout(time.Second*5))
reqUrl := "http://127.0.0.1:18001/swap-instructions"
res, err := client.NewRequest(context.Background()).
SetQueryParams(map[string]string{
"a": "b",
"name": "qwe123",
"time": "100",
}).
SetContentType(ContentTypeJSON).
SetHeaders(map[string]string{
"Api": "ok",
}).
SetBody(map[string]any{
"hello": "world",
"id": 5,
}).
Post(reqUrl)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", string(res.GetBody()))
fmt.Println(res.Header.String())
fmt.Println(res.Header.StatusCode())
}