I'm doing an API CALL
width POST
method either with Axios
or Fetch
but send the wrong Content-Type
on Android.
Send application/json; charset=utf-8
instead of application/json
It's working fine on iOS and GET
method seems to work well on both platform.
1) My App was created with Create-React-Native App and working with Expo
2) What I've tried so far :
- I read a lot of topics (github / stackoverflow) with some changes to do : in the headers, send another content-type, changes received data in
Postman
, etc- UsingAxios
orFetch
Example: 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
Code I tried (basically the same)
fetch('URL', {
method: 'POST',
headers: {
'TOKEN': 'TOKEN',
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
}).then((response) => console.log(response))
or
axios({
method: 'post',
url: LOGIN_API_URL,
headers: {
'Content-type': 'application/json',
'TOKEN': 'MyTestToken',
},
data: data,
}).then((response) => {console.log(response.data)})
The error I get :
{title: "ERROR", code: "invalid ContentType", description: "Content-Type expeced: application/json, Content-Type received: application/json; charset=utf-8", success: false}
I would like to send the right content-type: 'application/json'
for both platform : ios and android
If I missed some topics with the answer, sorry :)