Как я могу решить ошибку Bad Request 400 в React? - PullRequest
0 голосов
/ 15 марта 2020

Когда я отправляю этот запрос от Почтальона в SpringBoot, он работает.

        "location": "New Jersey",
        "category": {
            "name": "Travel",
            "id": 1
        },
        "expensedate": "2020-03-17",
        "descript": "New York City"

}

Но, когда я отправляю запрос от ReactJS, он говорит: 400 Плохой запрос

const item1={
            descript : event.target.description.value,
            category:{
                 id:1, name:event.target.category.value
             },
            expensedate : event.target.date.value,
            location : event.target.location.value
        }
        console.log(event.target.category.key);
        console.log(item1)


        await fetch(`/api/expenses`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'},
            body: JSON.stringify(item1)
        })

SpringBoot

@PostMapping("/expenses")
    Expense  createExpense(@RequestBody Expense expense){
        return this.expenseRepository.save(expense);
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...