Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios calculating wrong Content-Length #6309

Open
angelalawrence123 opened this issue Mar 19, 2024 · 2 comments
Open

Axios calculating wrong Content-Length #6309

angelalawrence123 opened this issue Mar 19, 2024 · 2 comments

Comments

@angelalawrence123
Copy link

Section/Content To Improve

I'm using Postman to access an API and on checking console the requested data was calculated as below by Postman :

image

I used exactly the same request body and headers and tried accessing that POST endpoint but I got a 403 error which depends on content-length and on checking the length calculated by Axios is different as compared to Postman one :

image

How can that be fixed?

Suggested Improvement

How it is calculating the same?

Relevant File(s)

No response

@justindhillon
Copy link

For anybody trying to look at this issue, content length is calculated in lib/adapters/http.js.

@justindhillon
Copy link

@angelalawrence123 , this is a pretty big diffrence between postman and axios. You should make sure that everything is good on your side:

  1. Ensure that the content of the request body is identical between Postman and Axios. Even small differences in payload content, such as whitespace or encoding, can result in different byte lengths.

  2. Check that both Postman and Axios are serializing the request body in the same format. For example, if you're sending JSON data, make sure that the serialization process is consistent and produces the same result in both environments.

  3. Verify that the Content-Type header and any other relevant headers are identical between Postman and Axios.

  4. Ensure that character encoding settings are consistent between Postman and Axios. Encoding differences can lead to variations in byte length, especially for non-ASCII characters.

If you have snippets of your code, I will have an easier time diagnosing your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants