"Handler crashed with error runtime error: invalid memory address or nil pointer dereference", but POSTMAN is ok! Why this happens?

"Handler crashed with error runtime error: invalid memory address or nil pointer dereference", but POSTMAN is ok! Why this happens?

我使用 vue,分别负责前端和后端。我向我的服务器发送 post 请求并收到 403 错误代码消息 (notAllowed)。但是在 postman 中我得到了 objects 并且很好。

Vue 和 Vuex

我的 axios post 请求:

const response = await this.$axios.post(`http://localhost:8000/v1/org/${params.organization}/kkms/${params.kkm}/closeShift`,{
  headers : { 
     'token' : this.state.token.value
}});

我知道我还应该在 headers 中使用其他属性,如 'Content-Type' 等,但我知道它在其他请求中仅与“令牌”属性 配合使用效果很好。我想知道是后端问题还是前端问题?

看来你的axios请求有误。 您收到 403,这意味着您未获得授权(或者有时是其他原因,请检查问题中的评论以及此处的评论)。

axios docs 中所示,post 请求如下所示: axios.post(url[, data[, config]]).

它接受配置(因此 headers)作为第三个参数,而您将其设置为第二个参数。添加一个空的 FormData object 作为第二个参数,然后将您的配置转移到第三个参数。

const fakeData = new FormData();
const response = await this.$axios.post(`http://localhost:8000/v1/org/${params.organization}/kkms/${params.kkm}/closeShift`,
fakeData,
{
  headers : { 
               'token' : this.state.token.value
             }
});