首页 > 解决方案 > Nativescript-Vue MobileApp:Axios 返回状态:null 和数据:“”

问题描述

我正在使用 Nativescript-Vue 制作一个本机应用程序,在我的第一个组件中,我启动了一个简单的发布请求,它确实有效(我在桌面版本上对其进行了测试)。但是由于我忽略的原因,响应存在问题。我的回复显示请求已成功发送参数,但我得到一个状态:null 和一个数据:“”。你们中的一些人知道我该如何解决这个问题吗?

对于正在阅读本主题的任何人,感谢您抽出宝贵的时间,任何线索都将是可观的 :)

axios({
method: 'post',
url: url,
data: querystring.stringify({
grant_type: config.grant_type,
username: config.API_username,
password: config.API_password,
APIKeys: config.API_key
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then((response) => {
alert(JSON.stringify(response, null, 4));

})
.catch((error) => {
alert(JSON.stringify(error, null, 4));
});

标签: javascriptvuejs2axiosnativescript-vue

解决方案


@RandyCasburn 感谢您的回复 Randy Casburn 先生,我没有从 API 中得到任何错误。我与一位同事讨论了这个话题,他告诉我,使用您提供给我的代码,API 没有收到请求。他认为这是因为您设置为 application/json 的内容类型,我们的 API 只接受 application/x-www-form-urlencoded,之后我尝试通过将内容类型更改为 application/x-www- form-urlencoded,但我没有得到回应,我不确定是否收到了请求。我们使用 Express API,使用 axios 进行调用。我的本机应用程序代码与我的桌面浏览器相同,但我从本机应用程序中删除了它。


推荐阅读