mycommon/myhttp/fasthttpc/httpclient_test.go

40 lines
714 B
Go

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())
}