From aea016f2f86064e587bf1724551883ddc724b31f Mon Sep 17 00:00:00 2001 From: liufuguo <595726017@qq.com> Date: Fri, 19 Aug 2022 16:19:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86header=E5=A4=B4?= =?UTF-8?q?=E4=BD=BF=E7=94=A8application/x-www-form-urlencoded=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=9C=80=E4=BC=A0=E5=85=A5Content-Length=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E7=84=B6=E5=90=8E=E7=AB=AF=E6=97=A0=E6=B3=95=E8=8E=B7?= =?UTF-8?q?=E5=8F=96body=E4=B8=AD=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utools/preload.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/utools/preload.js b/utools/preload.js index 753319c..a96e85e 100644 --- a/utools/preload.js +++ b/utools/preload.js @@ -21,7 +21,7 @@ sendRequest = function (args, callback, errorCallback) { port: myURL.port === "" ? (args.url.startsWith('https') ? 443 : 80) : myURL.port, path: myURL.pathname + myURL.search, method: args.method, - headers: filterHeader(args.headers), + headers: handleHeader(args.headers, args.body), }; let request; if (args.url.startsWith('https')) { @@ -42,11 +42,14 @@ sendRequest = function (args, callback, errorCallback) { } } -let filterHeader = function (headers) { +let handleHeader = function (headers, body) { let newHeaders = {} for (const key in headers) { + if ("Content-Type" === key && headers[key] === "application/x-www-form-urlencoded" && body !== undefined) { + newHeaders['Content-Length'] = Buffer.byteLength(body) + } if ("Accept-Encoding" !== key) { - newHeaders[key] = headers[key] + newHeaders[key] = headers[key]; } } return newHeaders