android - Nativescript-Vue 和 Axios 工作功能导致“错误:请求失败,状态码 429”
问题描述
问题:在调用使用 axios 的 vue 方法(通过@tap)时,我收到以下错误:“错误:请求失败,状态码 429”
我在网站上使用了相同的方法,它按预期工作(除了 async/await 部分,它是从建议中添加的 - 请参阅相关部分的评论)。
模拟器 (Pixel 2 API 28) 可以访问网络。
关于我的应用程序设置的信息:
@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(页面模块):
// 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);
}
}
}
我怀疑由于某种原因这不是编码问题,而是缺乏模拟器对我的应用程序的许可。
提前感谢您的任何帮助/建议!
解决方案
看来,毕竟大多数答复都是正确的。
谷歌似乎拒绝从 apk 中直接调用谷歌翻译(至少通过 axios)。在浏览器中它仍然有效,所以我相信(虽然不确定)这是原因。
谢谢大家的见解!
推荐阅读
- flutter - 自定义 IBM Watson Visual Recognition 服务与 Flutter/Dart 的集成
- angular - 上传到 AngularFireStorage 后如何使用 getDownloadUrl() 检索下载 URL
- apache-kafka - kafka 客户端可以连接到在 docker 容器中运行的 kafka 服务器
- javascript - 如果 localstorage access_token 未定义,如何重定向回登录页面
- monetdb - 是否可以使用 monetdb/e 打开常规的 monetdb 数据库目录?
- .net - 如何注入asp.net mvc区域
- c# - 确定统一旋转角色的方向?
- python-3.x - 是否有生成具有相同灰度值的随机颜色的公式?
- spring - 如何找出spring boot starter web依赖中包含哪些jar
- python - 将页面添加到 Scrapy 缓存