简体   繁体   English

axios发布方法400错误的请求

[英]axios post method 400 bad request

I'm getting a JSON file, editing it and trying send it back to server. 我正在获取JSON文件,对其进行编辑,然后尝试将其发送回服务器。 But when I use post method it throws an error 400 bad request.In response shows "no template_id or no template_json presented". 但是,当我使用post方法时,它会引发错误400错误请求。响应显示为“未显示template_id或未显示template_json”。 What could be the problem? 可能是什么问题呢?

saveData() {
    const { data } = this.state
    let token = localStorage.getItem("token")
    axios
      .post(
        "http://dev.candidates.hrmessenger.com/stage/set-template",
        data,

        {
          headers: {
            "Content-Type": "application/json",
            Authorization: `Bearer ${token}`,
          },
        },
      )
      .then(res => {
        console.log(res)
      })
      .catch(error => {
        console.log(error)
      })
  }

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Please try to use this: 请尝试使用此:

data.template_id = 1; data.template_id = 1;

saveData() {
    const { data } = this.state
    data.template_id = 1;
    let token = localStorage.getItem("token")
    axios
      .post(
        "http://dev.candidates.hrmessenger.com/stage/set-template",
        data,

        {
          headers: {
            "Content-Type": "application/json",
            Authorization: `Bearer ${token}`,
          },
        },
      )
      .then(res => {
        console.log(res)
      })
      .catch(error => {
        console.log(error)
      })
  }

You missed the parameter template_id, or you need to ask from your API developer to send the documentations of the POST Method API. 您错过了参数template_id,或者您需要向API开发人员要求发送POST方法API的文档。

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

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