簡體   English   中英

POST 400 錯誤請求

[英]POST 400 Bad request

我是 django 和 reactjs 的新手,我正在嘗試使用 axios POST 請求,但我無法發送數據。 我收到控制台錯誤

POST http://localhost:8000/api/todos/ 400(錯誤請求)

這是我的 package.json

{
  "name": "myapp",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:8000/",
  "secure": false,
  "dependencies": {
    "axios": "^0.18.0",
    "bootstrap": "^4.3.1",
    "moment": "^2.24.0",
    "react": "^16.5.2",
    "react-datepicker": "^2.5.0",
    "react-datetime": "^2.16.3",
    "react-datetime-picker": "^2.4.0",
    "react-dom": "^16.5.2",
    "react-scripts": "2.0.5",
    "reactstrap": "^6.5.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

這是我使用 axios 的 App.js

 refreshList = () => {
        axios
        //   .get("/api/todos/", {
        //     headers: {
        //         'Content-Type': 'application/json',
        //         "Access-Control-Allow-Origin": "*"
        //     }
        // })
          .get("http://localhost:8000/api/todos/", { headers: {
                    'Content-Type': 'application/json',
                    "Access-Control-Allow-Origin": "*"
                }
            })
          .then(res => this.setState({ todoList: res.data }))
          .catch(err => console.log(err));
      };

如果您控制台記錄響應狀態,它應該為您提供更詳細的錯誤描述。

例子:

if(response) {
console.log(response.status)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM