Issue: upon calling a vue method (via @tap) that uses axios, I get the following error: "Error: Request failed with status code 429"
I use the same method on a website and it works as expected (except the async/await part, which was added from a suggestion - see the comment at the relative part).
The emulator (Pixel 2 API 28) has access to the web.
Info around my app's setup:
@package.json:
"dependencies": {
"@nativescript/theme": "^2.2.1",
"@vue/devtools": "^5.3.3",
"axios": "^0.19.2",
"nativescript-socketio": "^3.3.1",
"nativescript-toasty": "^3.0.0-alpha.2",
"nativescript-vue": "^2.6.1",
"nativescript-vue-devtools": "^1.4.0",
"tns-core-modules": "^6.5.1",
"vuex": "^3.3.0"
}
@AndroidManifest.xml:
// Suggestion from stackoverflow:
// https://stackoverflow.com/questions/55184243/how-to-call-axios-api-call-in-nativescript-application
<application
android:usesCleartextTraffic="true"
@npm ls --depth=0
├── axios@0.19.2
├── vue@2.6.11
├── vue-axios@2.1.5
├── xmldom@0.3.0
└── xpath@0.0.27
@main.js :
import Vue from 'nativescript-vue'
import App from './components/App'
import VueDevtools from 'nativescript-vue-devtools'
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueDevtools, VueAxios, axios)
@App.vue (the Page Module):
// Also tried: import axios from 'axios/dist/axios'; - As suggested from stack overflow:
// https://stackoverflow.com/questions/55184243/how-to-call-axios-api-call-in-nativescript-application
import axios from 'axios';
[...]
methods: {
// The reason I've made it 'async', was from a suggestion on S.O., that axios might return Error: the 429 error,
// due to simultaneous calls.
// https://stackoverflow.com/questions/54254235/axios-request-failed-with-status-code-429-but-it-is-working-with-postman
fetchit: async function () {
let xmls='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\
xmlns:web="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL">\
<soapenv:Header/>\
<soapenv:Body>\
<tns:GetWeatherInformation>\
<name:GetCityWeatherByZIP>65215</name:GetCityWeatherByZIP>\
</tns:GetWeatherInformation>\
</soapenv:Body>\
</soapenv:Envelope>';
try{
const result = await axios.get('https://translate.googleapis.com/translate_a/single?client=gtx&sl=el&tl=en&dt=t&q=πέντε')
.then(res=>{console.log("Sucess!", res);})
.catch(err=>{console.log("Here......................",err);})
return result;
}
catch (error) {
console.log("Try-Except Error = ", error);
}
}
}
I suspect that for some reason it's not a coding issue, rather lack of permission of the emulator to my app.
Thank you in advance for any help/suggestion!