简体   繁体   English

403 禁止在 Vue.js + CodeIgniter 4

[英]403 Forbidden in Vue.js + CodeIgniter 4

I created a simple api using CodeIgniter 4 that currently has 2 routes:我使用 CodeIgniter 4 创建了一个简单的 api ,目前有 2 条路线:

$routes->get('/expenses','Home::getAllExpenses');
$routes->post('/expenses','Home::addRecord');

I display the data using Vue, so the first one returns some json data about expenses while the second one should store the data from a form.我使用 Vue 显示数据,所以第一个返回一些有关费用的 json 数据,而第二个应该存储表单中的数据。

What happens is when I hit submit I get a 403 Forbidden for the post route.发生的情况是,当我点击提交时,我得到一个 403 Forbidden 用于发布路线。

The call is made like this:调用是这样的:

this.validationError = false;
                this.request.sum = this.sum;
                this.request.type = this.type;
                this.request.name = this.name;

                this.$http.post(base_api_url + 'expenses', this.request)
                    .then(function(response){
                        console.log(response);
                    });

The get request is ok and nothing on the CI forum helped me:(获取请求没问题,CI 论坛上的任何内容都没有帮助我:(

Could you check to see if your POST requests also includes cookies (in developer tools > network tab)?您能否检查一下您的 POST 请求是否还包括 cookies(在开发人员工具 > 网络选项卡中)? It's a fairly common problem that fetch/xhr libraries (like this.$http) do not send credentials (cookies) by default.默认情况下,fetch/xhr 库(如 this.$http)不发送凭据(cookies)是一个相当普遍的问题。 If the cookies are missing from your, you can enable sending credentials by:如果您的 cookies 缺失,您可以通过以下方式启用发送凭证:

Vue.http.options.credentials = true;

Assuming you are using Vue-resource (this.$http)假设您使用的是 Vue 资源 (this.$http)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM