我正在try 在Nativescript-vue
上构建一个小型应用程序,我有一个后端laravel
框架,用于api调用,需要调用它来获取相关数据.例如,如果用户想要登录,他需要通过api oauth/token
验证其凭据,所以我试图通过axios
调用它.下面是我的代码:
我的settings.js
文件包含.
export const authHeader = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
这是在我的axios调用中导入的:
const postData = {
grant_type: 'password',
username: user.email,
password: user.password,
client_id: clientId,
client_secret: clientSecret,
scope: '',
provider: provider
}
const authUser = {}
axios.post(authUrl, postData, {headers: authHeader}).then(response => {
console.log('Inside oauth/token url')
if(response.status === 200)
{
console.log('response received')
}
})
.catch((err) => {
if(err.response.status === 401){
reject('Validation error')
}
else
reject('Something went wrong')
})
当我try 使用命令tns debug android --bundle
构建时,我得到了chrome-devtools
,这表明:
深入挖掘,我可以看到标题正在通过,但这些只是暂时的:
正如你所看到的,我的应用程序中有console.log
个显示:
即使在编译时,我也会出现以下错误:
指导我怎样才能做到这一点.谢谢
Edit:
类似地,我使用了nativescript's
own http
documentation类似的东西:
const httpModule = require("http");
httpModule.request({
url: "http://iguru.local/oauth/token",
method: "POST",
headers: { "Content-Type": "application/json" },
content: JSON.stringify({
grant_type: 'password',
username: this.user.email,
password: this.user.password,
client_id: 'check',
client_secret: 'check',
scope: '',
provider: 'check'
})
}).then((response) => {
// Argument (response) is HttpResponse
console.log('Action called')
if(response.status === 200)
{
console.log('Response recieved')
}
}, (e) => {
console.log('Something went wrong')
});
我得到了同样的结果,而且我try 了服务器端ex http://confidenceeducare.com/oauth/token的api,结果恰好是一样的.普通Vue
应用程序对api的调用非常好.我猜nativescript
应用程序有问题.我需要进口更多的东西吗?我受够了.
如果有人认为我的api端点被 destruct 了,我try 使用示例https://httpbin.org/post
中提到的URL:
以及:
当我在postman
中判断我的api时,它正在那里工作,我至少得到了一个带有状态代码的响应:
Edit 2: