Using beforeRequest to alter the body content. Content-length invalid based on documentation example. #2197
simplecommerce
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I just wanted to mention that in my existing project, I tried to follow the following example and it didn't work for me in my case.
https://github.com/sindresorhus/got/blob/main/documentation/9-hooks.md#beforerequest
In my case, when I added my key directly in the json body and logged the options being sent, the content-length differed from doing it in the method explained above.
I had to use
options.headers["content-length"] = Buffer.byteLength(options.body)
instead ofoptions.body.length.toString()
to make it work.Just felt like I should mention it in case other people have the same issue.
Beta Was this translation helpful? Give feedback.
All reactions