From 24ae356028460a41618a084b11377b0495d812c1 Mon Sep 17 00:00:00 2001 From: TurtleRuss0 Date: Wed, 4 Sep 2024 00:03:41 +0000 Subject: [PATCH] fix: buildCurlRequest() replace req.Body with req.GetBody() --- util_curl.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util_curl.go b/util_curl.go index 6eab3b4b..7484762f 100644 --- a/util_curl.go +++ b/util_curl.go @@ -31,7 +31,12 @@ func buildCurlRequest(req *http.Request, httpCookiejar http.CookieJar) (curl str // 3. Generate curl body if req.Body != nil { - buf, _ := io.ReadAll(req.Body) + // httpclient.Do method will read the entire body and make it empty + // thus using req.GetBody() instead of req.Body since req.Body + // is empty after Do method. + // body here is a copy of original body + body, _ := req.GetBody() + buf, _ := io.ReadAll(body) req.Body = io.NopCloser(bytes.NewBuffer(buf)) // important!! curl += `-d ` + shellescape.Quote(string(buf)) }