Похожие чаты

Hey guys hope you are having a good time ,


when i do an api call with axios like that :
axios.post("/api/post", body).then(r => console.log("r : ", r)).catch(e => console.log("e : ", e))
it works and api return an status of 200 , but when i do the same with fetch like this :
fetch("/api/post", {
method: "POST", body: body, headers: {
'Content-Type': 'application/json'
}
}).catch(e => console.log("e : ", e)).then(r => console.log(r))
the api returns a 400 , i tried it with other tools like postman and ... and they work fine as well but the fetch don't , why do you think this is happening ?

11 ответов

28 просмотров

Maybe read the error message of the response?

mohammad- Автор вопроса
Edwing123
Maybe read the error message of the response?

just says a bad request doesn't give much

mohammad- Автор вопроса
mohammad
yes

What can trigger a bad request? Bad request body?

what's body?

mohammad- Автор вопроса
Edwing123
What can trigger a bad request? Bad request body?

i checked this as well , and the thing is it doesn't even get to the handler that i have written , it is just being rejected by the framework i'm using , so i'm guessing it's probabaly bcuz of the request headers that fetch is creating for the request (just a guess) but i'm not sure what would cause these to act so different

@TRGWII, is this a problem that .catch comes before .then?

mohammad- Автор вопроса
Edwing123
@TRGWII, is this a problem that .catch comes befor...

nah , catch was after then , i just changed it's location for a test , it didn't work in either one

axios might be adding additional headers, like Content-Length, Accept, etc, and I would recomment JSON.stringifying it

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
11
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
11
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Карта сайта