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

449
Vistas
Necesita convertir PHP Curl Request a JavaScript (Node.js)

Actualmente tengo una solicitud Curl en PHP como la siguiente,

 $url = "http://localhost:8500/v1/catalog/service/api?passing&tag=%2Fu%2Fdeepak%2F211%2Flocalhost" $ch = curl_init($url); function _exec($ch) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $response = curl_exec($ch); $info = curl_getinfo($ch); if ($info['http_code'] !== 200) { if ($info['http_code'] === 404) { throw new Exception('Unable to find requested requested Consul API: ' . $info['url']); } else { $message = 'Url: ' . $info['url']; $error = curl_error($ch); if (! empty($response)) { $message .= ' -- Response: ' . $response; } if (! empty($error)) { $message .= ' -- Error: ' . $error; } throw new Exception('Failed to call Consul API: ' . $message); } } curl_close($ch); return json_decode($response); }

Necesita convertir este mismo código en JavaScript y ejecutarlo en Node.js. En su mayoría, encontré soluciones usando solo AJAX. Cualquier ayuda sería muy apreciada.

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

0

Puede usar JavaScripts Fetch API (disponible en su navegador) para realizar solicitudes de red.

Si usa node, deberá instalar el paquete node-fetch.

 const url = "http://localhost:8500/v1/catalog/service/api?passing&tag=%2Fu%2Fdeepak%2F211%2Flocalhost"; const options = { headers: { //Authorization: "Bearer 6Q************" } }; fetch(url, options) .then( res => res.json() ) .then( data => console.log(data) );
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