Axios: Kesalahan: Permintaan gagal dengan kode status 400

Dibuat pada 24 Jun 2017  ·  3Komentar  ·  Sumber: axios/axios

Saya menggunakan axios dan mencoba memposting ke localhost:3000/posts dan mendapatkan kesalahan ini di atas. Berikut kodenya:

import axios from 'axios';
import {
  GET_ALL_POSTS,
  GET_POST,
  CREATE_POST,
  DELETE_POST,
  UPDATE_POST
} from './types';

const ROOT_URL = 'http://localhost:3000';

export function createPost({content, title}, cb) {
  return function(dispatch) {
    axios.post(`${ROOT_URL}/posts`, {content, title})
      .then((response) => {
        console.log(response);
        dispatch({
          type: CREATE_POST,
          payload: response
        });
      })
      .then(() => cb())
      .catch((error) => {
        if(error.response) {
          console.log(error.response);
        }
        console.log("Problem submitting New Post", error);
      });
  }
}

Komentar yang paling membantu

Hai,
Request failed with status code 400 berarti permintaan telah dibuat, tetapi server mengembalikan respons dengan kode HTTP 400 (Permintaan Buruk).

Semua 3 komentar

Hai,
Request failed with status code 400 berarti permintaan telah dibuat, tetapi server mengembalikan respons dengan kode HTTP 400 (Permintaan Buruk).

Saya menutup PR ini karena sepertinya tidak ada masalah di Axios tetapi di server web Anda.

Pengguna redux thunk (Middleware) tempat Anda dapat menerapkan logika asinkron

Apakah halaman ini membantu?
0 / 5 - 0 peringkat