Axios post request network error on android using React-Native

Rani
Oct 19, 2022

I finally found what’s wrong — it’s the Content-Type request header.
If you don't set it explicitly, then the default value is set here to application/x-www-form-urlencoded -> https://github.com/axios/axios/blob/v0.27.2/lib/defaults/index.js#L10 and that apparently makes the request fail on Android, but not on iOS.
Setting the 'Content-Type': 'multipart/form-data' explicitly fixes the error.
It was working in 0.26.1 because this code was removing the Content-Type header: https://github.com/axios/axios/blob/v0.26.1/lib/adapters/xhr.js#L32

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response