Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

706
Vistas
How can I get response from http url by axios (or request)

I am trying to fetch data from jsonplaceholder by axios and request. I found that when I pass 'http' url to axios, it returned 'Network Error'.

code

import axios from "axios"
const url='http://jsonplaceholder.typicode.com/todos/1';
axios.get(url)
  .then((res) => console.log(res))
  .catch((err) => console.log(err))

response

AxiosError: Network Error
  message: "Network Error"
  name: "AxiosError"
  code: "ERR_NETWORK"
  config: (15) {transitional: {...}, adapter: xhrAd...}
  request: XMLHttpRequest {data: undefined}
  response: XMLHttpRequest {data: undefined}

Or you can see all responses I have tried in these images.

  • Axios with http url
  • Axios with https url
  • Request with http url
  • Request with https url
  • and this image use python requests to confirm that this API can be called by using both http and https

How can I get response from http url by axios (or request)?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It takes some time for the request to return. Hence you must call it asynchronously:

async function getSomeDataWithAsync() {
  /*
    Using await inside a function marked as async tells the browser to HOLD UP
    on running any more of the functions code until the promise is returned and the 
    value is set in the response variable.
  */
    const response = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
  /*
    This is the same exact point as the first .then in the getSomeData function above 
    this one.  You can see async/await is slightly less verbose.
  */
  console.log(response)
  
  /*
    At this point you can extract the data from the resolved promise
    and use it.
  */
  const { data } = response;
  console.log(data);
}

getSomeDataWithAsync();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda