I test it successfully by using postman. I get status code 200.
Using Axios in React Native 0.60.5
But when I test it on react native project, I get Error: Request failed with status code 415
I have no idea why.
Here is my axios code:
ApiServices.ts
import axios from 'axios';
const instance = axios.create({
baseURL: 'http://192.168.1.161:5000/',
timeout: 3000,
});
instance.interceptors.request.use((config) => {
return config;
}, (error) => {
// handle error
return Promise.reject(error);
});
instance.interceptors.response.use((response) => {
return response;
}, error => {
// handle error
return Promise.reject(error);
});
export const Get = async (api: string, params: object) => {
console.log('api', api); // Account
console.log('params', params); // { userAccount: "0989257556", userPwd: "12345" }
return new Promise((resolve, reject) => {
instance.get(api, params).then(res => {
resolve(res.data);
}).catch(error => {
reject(error);
});
})
};
I use the function like this:
export const testApiGet = () => {
const userAccount = '0989257556';
const userPwd = '12345';
Get('Account', { userAccount, userPwd }).then(res => {
console.log('res ->', res);
}).catch(err => {
console.log('err ->', err);
});
}
Any help would be appreciated.