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

327
Visualizações
POST http://localhost:3001/[object%20Promise] 404 (Not Found) React Axios

Here is my code to send data to the server but I always get this Error.

let data = {
        "email": "test@gmail.com",
        "language": "en",
        "country": "en",
        "istestentry": false
    };

    let jsonData = JSON.stringify(data);
    let encodedData = encodeURIComponent(jsonData);
    let url = "https://example.org/b/receiver/external";
    let fetchUrl = url + "?datajsonstr=" + encodedData + "&_=" + (new Date()).valueOf();
    let datafetch = fetch(fetchUrl);

    const [fetchedData, setFetchedData] = useState('');

    async function fetchData(){
        const  {data} = await axios.post(
            datafetch
        )
        setFetchedData(data)
    }

    useEffect(() => {
        fetchData()
    }, [])

    const handleSubmit = (event) => {
        event.preventDefault();
        fetchData()
};

I don't know how to solve this problem.

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

0

You are trying to send a promise instead of a stringified data. let datafetch = fetch(fetchUrl); gives you a promise. Also sending data through params is done with get requests. So I assume that you may need to make a get request:

let fetchUrl = url + "?datajsonstr=" + encodedData + "&_=" + (new Date()).valueOf();

const [fetchedData, setFetchedData] = useState('');

async function fetchData(){
    const  {data} = await axios.get(fetchUrl)
    setFetchedData(data)
}

(P.S. get or post depends on how your api handles requests. You can choose the correct one)

about 4 years ago · Juan Pablo Isaza Relatório

0

I solved it like this. if you don't want to use Axios, you can solve it also like this.

const [dataDone, setDataDone] = useState(false);

useEffect(() => {
    let data = {
        "email": "test@gmail.at",
        "language": "de",
        "country": "de",
        "istestentry": false
    };

    let jsonData = JSON.stringify(data);
    let encodedData = encodeURIComponent(jsonData);
    let url = "https://org.com;
    let fetchUrl = url + "?datajsonstr=" + encodedData + "&_=" + (new 
    Date()).valueOf();
    let datafetch = fetch(fetchUrl);

    datafetch.then(data => {
        setDataDone(true)
    })
}, [])
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