Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
La propiedad de respuesta Node-fetch Promise se imprime como indefinida

Sé que se han hecho muchas preguntas similares (ver here y here ), pero probé las soluciones mencionadas allí. Estoy tratando de averiguar por qué mi respuesta de búsqueda de nodo no se comporta como se esperaba. Aquí hay una versión simple del código:

 fetch(new URL("https://www.stackoverflow.com")).then(theResponse =>{ console.log("This prints OK: "); console.log(theResponse.headers); console.log("But this prints as undefined:"); console.log(theResponse.headers["content-encoding"]); return theResponse; })

Los encabezados impresos son:

 { 'accept-ranges': 'bytes', 'cache-control': 'private', connection: 'close', 'content-encoding': 'gzip', 'content-security-policy': "upgrade-insecure-requests; frame-ancestors 'self' https://stackexchange.com", etc. }

¿Por qué theResponse.headers["content-encoding"] regresa como undefined ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe usar el método .get del objeto Headers :

 console.log(theResponse.headers.get("Content-Encoding"));

Tenga en cuenta que, a diferencia de un Map o un acceso a la propiedad de un objeto, funciona sin distinguir entre mayúsculas y minúsculas.

about 4 years ago · Juan Pablo Isaza Report

0

también puede usar el método getAll of Headers object, devuelve una matriz

console.log(theResponse.headers.getAll("Content-Encoding"));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!