Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

770
Visualizações
How to send curl request in react/javascript using fetch?

I want to make a request..This is the curl request

curl --location --request POST '2.2.2.22:343/sudun/cars' \
--header 'Authorization: Bearer sdswmaiqwasae*********' \
--header 'Content-Type: application/json' \
--data-raw '{
    "user": "sdsffwefwefwssdsds",
    "numberofunits": 4,
    "price": 0
}'

This is the way I am doing.

const url = "2.2.2.22:343/sudun/cars";

const options = {
  headers: {
    "Authorization": "Bearer sdswmaiqwasae*********",
    "Content-Type": "application/json"
  }
};

fetch(url, options)
  .then( res => res.json() )
  .then( data => console.log(data) );

It is not working...I know i have not added --data-raw part ...I don't know how to do that..

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you can try like this if you are using fetch.

var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer sdswmaiqwasae*********");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "user": "sdsffwefwefwssdsds",
  "numberofunits": 4,
  "price": 0
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("2.2.2.22:343/sudun/cars", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda