Ich verwende Axios und versuche, auf localhost:3000/posts zu posten, und erhalte diesen Fehler oben. Hier ist der Code:
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);
});
}
}
Hey,
Request failed with status code 400
bedeutet, dass die Anfrage erstellt wurde, aber der Server eine Antwort mit dem HTTP-Code 400 (Bad Request) zurückgegeben hat.
Ich schließe diese PR, da es kein Problem in Axios, sondern in Ihrem Webserver zu sein scheint.
Benutzer -Redux-Thunk (Middleware), in dem Sie asynchrone Logik anwenden können
Hilfreichster Kommentar
Hey,
Request failed with status code 400
bedeutet, dass die Anfrage erstellt wurde, aber der Server eine Antwort mit dem HTTP-Code 400 (Bad Request) zurückgegeben hat.