javascript - 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));
});
解决方案
@RandyCasburn 感谢您的回复 Randy Casburn 先生,我没有从 API 中得到任何错误。我与一位同事讨论了这个话题,他告诉我,使用您提供给我的代码,API 没有收到请求。他认为这是因为您设置为 application/json 的内容类型,我们的 API 只接受 application/x-www-form-urlencoded,之后我尝试通过将内容类型更改为 application/x-www- form-urlencoded,但我没有得到回应,我不确定是否收到了请求。我们使用 Express API,使用 axios 进行调用。我的本机应用程序代码与我的桌面浏览器相同,但我从本机应用程序中删除了它。
推荐阅读
- java - 将侦听器添加到不存在的值
- javascript - JavaScript 解构并分配给新对象
- elasticsearch - elasticsearch on linux for windows 日志
- python - 使用 boto3 库从 AWS S3 存储桶中读取 XML 文件的内容
- c - 没有加速结果的高斯消元
- mysql - 元键:返回 NULL 的值字段
- c# - 如何在c#中按高分对存储在文本文件中的数据进行排序
- angular - 激活change事件时如何获取下拉列表对应的json?
- keras - 检查目标时出错:预期 dense_49 的形状为 (2943,) 但得到的数组形状为 (1,)
- javascript - jquery对话框不加载iframe