Похожие чаты

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 ответов

34 просмотра

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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта