如何修复axios post请求上的错误422?

edqdpe6u  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(577)

我正在尝试使用axios请求填充一个已经构建好的php数据库,但是我一直收到422错误,我不明白我遗漏了什么。你能帮我吗:)这是我得到的错误:

xhr.js:177 POST URL/data 422 (Unprocessable Entity)

这是数据库的请求后模式:

"post": {
    "summary": "Post new data row",
    "description": "Post new data row",
    "requestBody": {
      "required": true,
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "data": {
                "type": "string",
                "example": "{\"test\":1}"
              },
              "type": {
                "type": "string",
                "example": "1"
              },
              "status": {
                "type": "integer",
                "example": 1
              }
            },
            "required": [
              "data",
              "type"
            ]
          }
        }
      }
    },
"responses" :{
 "422": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "error": {
                    "type": "string",
                    "example": "Invalid input"
                  }

这是我的代码,我有几个开关盒,它们都应该以相同的方式工作:

case "rezervariContact" : {
            const {type, titlu, description, phone, email} = this.state;
            const contactData = {
                type: this.state.type,
                data:{
                    type, 
                    data :{
                        titlu, description, phone, email
                    }
                },
                status:true
            }
            data = {...contactData};
        }
    }
    await axios({
        method: "post",
        headers: { "Content-Type": "application/json",
                    'Accept': '*/*' },
        body:data,
        url : 'http://ms.homens.tricu.ro/data'
      })
        .then(function (response) {
          console.log("RespResolved::",response.config.params);
        })
        .catch(function (response) {
          console.log("catchErrResp::",response);
        });
}

如果你能发现什么,请告诉我。

相关问题