运行以下命令:
$ laravel new app
$ composer install
$ php artisan make:auth
填写新的数据库信息。
$ php artisan migrate
$ yarn install
点击/注册并创建一个新用户,现在我已登录Laravel。我打开JavaScript控制台,然后写下以下内容:
> axios.get('/api/user').then(res => console.log(res.data));
我得到:GET http://127.0.0.1:8000/api/user 401(未经授权)
我的标题是:
GET /api/user HTTP/1.1
Host: 127.0.0.1:8000
Connection: keep-alive
Authorization: QmU4zkAA5N9BVoZsJEX4cQIn3UHwzNmFEwZkl8vy
X-XSRF-TOKEN: eyJpdiI6ImFcL1JYeFZnV1piVG5jRFZYWnFKVUpnPT0iLCJ2YWx1ZSI6ImczYmxMZW1Fa2xPaVRwUVQyUTJ0Wm1UNHo0NWNxZkRJazFKY3o3R05XTE9KcVNyMDlzOE80NitpZ1FBcjJOUXJGYXl1bnJyN2hFMksyR2RcL1RobWNcL0E9PSIsIm1hYyI6IjY5NGUzNzc1MjNmODdiYmJlYzI2YzI4YWQzMGQwMWY2MWVjYmUzZThkNDZjYWEzM2MxMzFlNmRkMzRlY2Q0OTcifQ==
X-CSRF-TOKEN: QmU4zkAA5N9BVoZsJEX4cQIn3UHwzNmFEwZkl8vy
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Accept: application/json, text/plain, */*
X-Requested-With: XMLHttpRequest
Referer: http://127.0.0.1:8000/home
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: es-ES,es;q=0.8,en;q=0.6,pt;q=0.4
Cookie: XSRF-TOKEN=eyJpdiI6ImFcL1JYeFZnV1piVG5jRFZYWnFKVUpnPT0iLCJ2YWx1ZSI6ImczYmxMZW1Fa2xPaVRwUVQyUTJ0Wm1UNHo0NWNxZkRJazFKY3o3R05XTE9KcVNyMDlzOE80NitpZ1FBcjJOUXJGYXl1bnJyN2hFMksyR2RcL1RobWNcL0E9PSIsIm1hYyI6IjY5NGUzNzc1MjNmODdiYmJlYzI2YzI4YWQzMGQwMWY2MWVjYmUzZThkNDZjYWEzM2MxMzFlNmRkMzRlY2Q0OTcifQ%3D%3D; laravel_session=eyJpdiI6ImRtZzdPUElaY1dcL1hLWHJPZVkwaW5RPT0iLCJ2YWx1ZSI6IitrVm9GOW5TQTdWZldJY3VlWU5EeWVBRitIVjVrYXpkWGhmWmJlWjJrTmlCWVZ0VUkwdEFrY3VoU2ZCMnRKMnlCV29pQ3NVa0ROdHEyaXlLMWhuWTd3PT0iLCJtYWMiOiJhMGE0ZTg5NTlkYzlkYmM2MjBhMjNmYTA2ZjUyYmE0N2RlMzVmNjA4Zjg3MDZhMDEzMDM1MGJjOWUzNzg5NDk3In0%3D
任何经历过类似情况的人?