• Empleos
  • Sobre nosotros
  • Empleos
    • Inicio
    • Empleos
    • Cursos y retos
  • Empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

553
Vistas
¿Cómo puedo obtener una respuesta de http url por axios (o solicitud)?

Estoy tratando de obtener datos de jsonplaceholder por axios y request. Descubrí que cuando paso la URL 'http' a axios, devuelve 'Error de red'.

código

 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))

respuesta

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

O puedes ver todas las respuestas que he probado en estas imágenes.

  • Axios con URL http
  • Axios con URL https
  • Solicitud con url http
  • Solicitud con url https
  • y esta imagen usa solicitudes de python para confirmar que esta API se puede llamar usando http y https

¿Cómo puedo obtener una respuesta de http url por axios (o solicitud )?

over 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

La solicitud tarda un tiempo en devolverse. Por lo tanto, debe llamarlo de forma asíncrona:

 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();
over 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda