Laravel+Passport作为oAuth服务器,axios+cordova作为客户端
Laravel+Passport as oAuth server and axios+cordova as a client
你好程序员,
我的目标是在 laravel 上制作一个 API,以便用户 get/post 其他设备/客户端上的数据。客户端代码在 axios+cordova 上。我是在正确的道路上还是做错了。第一次在 Laravel + Passport API 以及 axios + cordova 上也是如此。
服务器端
I setup server with the help of Laravel 5.6.4 + Passport and created token on Postman successfully.
客户端
Now I am trying to access user data through api/user default route in separate project, here is my code for that
AUTH_TOKEN = 'Bearer eyJ0eXAiOiJKV1QiLCJ...';
axios.defaults.baseURL = 'http://sbs-api.dev';
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.get('/api/user')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
but I'm unable to get user data instead of getting this error Network Error and/or Preflight Error. On Postman I am getting the data with same token.
Please tell me what is wrong with this code and/or provide some tutorials if possible.
Okay my bad here is the reason why am I getting issue, I was using virtual url http://sbs-api.dev instead of original url http://localhost/sbs-api/public
My sincere apology for this stupid and simple mistake O.o :)
你好程序员,
我的目标是在 laravel 上制作一个 API,以便用户 get/post 其他设备/客户端上的数据。客户端代码在 axios+cordova 上。我是在正确的道路上还是做错了。第一次在 Laravel + Passport API 以及 axios + cordova 上也是如此。
服务器端
I setup server with the help of Laravel 5.6.4 + Passport and created token on Postman successfully.
客户端
Now I am trying to access user data through api/user default route in separate project, here is my code for that
AUTH_TOKEN = 'Bearer eyJ0eXAiOiJKV1QiLCJ...';
axios.defaults.baseURL = 'http://sbs-api.dev';
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.get('/api/user')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
but I'm unable to get user data instead of getting this error Network Error and/or Preflight Error. On Postman I am getting the data with same token.
Please tell me what is wrong with this code and/or provide some tutorials if possible.
Okay my bad here is the reason why am I getting issue, I was using virtual url http://sbs-api.dev instead of original url http://localhost/sbs-api/public
My sincere apology for this stupid and simple mistake O.o :)