Похожие чаты

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

15 просмотров

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

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

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

А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
зачем же переименовывать ? чтобы кол-во участников возросло или вдруг IBM от этого снова на свифте начнет кодить ? Я не понимаю что страшного в том что свифт гавно, если это т...
Oleh Nerzh
10
Is Kadena onto something special? No one really knows. Good luck!
Bright Uncle Stephen EqualBet
40
Гайз, кто-нибудь пробовал запустить probe-rs под камень, которого нет в probe-rs? Мб есть какой-нибудь пример у кого... Через target-gen попробовал сгенерировать chip-descript...
Максим Смирнов
2
здравствуйте. совершаю вот такую вещь: strcpy(line, (char)current_number); где current number — неподписанный шорт, line — массив чаров. ругань следующая: main.c:29:30: error...
Roberto's Ширгозиев
13
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
@MrMiscipitlick А можешь макрос написать, который будет вычислять смещение относительно переданных меток? Просто .label1-.label2, и вернуть значение.
КТ315
35
isn't utxo commitements pretty close though if someone wanted to get it over the finish line? my understanding is that most of the ground work was already down by verde
Luke High - Rabbi Of Bcash High Rabbi Of Bcash
23
Можно попросить небольшое ревью кода? Тут немнога, я ничего интереснее не придумал, чем написать аналог tree в качестве практики с cmake. https://github.com/hrimov/tree-unix/...
Andrew Hrimov
11
Всем привет. Ребят подскажите пожалуйста. Вопрос по дизасемблировани. Начну с начала. У меня есть скомпилированная программа на ГО (я разработчик) - в ней есть защита лицензии...
Zloy
11
Карта сайта