From 83e815bd1f43732658f34ed31ed634106882a2ec Mon Sep 17 00:00:00 2001 From: Yun Date: Sat, 23 Mar 2024 13:11:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- curlx.go | 4 +++- params.go | 9 +++++++++ post.go | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 post.go diff --git a/curlx.go b/curlx.go index cf8907b..ecb36ae 100644 --- a/curlx.go +++ b/curlx.go @@ -182,7 +182,9 @@ func (c *Curlx) SendWithResponee(ctx context.Context, ps ...Param) Response { if n == 0 { break } - body = append(body, buf...) + // 读取n个字节 + body = append(body, buf[:n]...) + // body = append(body, buf...) } default: body, _ = io.ReadAll(resp.Body) diff --git a/params.go b/params.go index a295159..80cced1 100644 --- a/params.go +++ b/params.go @@ -106,6 +106,15 @@ func SetUserAgent(userAgent UserAgent) Param { } } +/** + * 设置Referer + */ +func SetReferer(referer string) Param { + return func(param *ClientParams) { + param.Headers["Referer"] = referer + } +} + /** * 设置cookies */ diff --git a/post.go b/post.go new file mode 100644 index 0000000..ef6e8c1 --- /dev/null +++ b/post.go @@ -0,0 +1,10 @@ +package curlx + +import ( + "io" + "net/http" +) + +func Post(url string, contentType string, body io.Reader) (resp *http.Response, err error) { + return http.Post(url, contentType, body) +}