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

145
Views
JavaScript: Obtener encabezados: el objeto literal no agrega un encabezado personalizado, el nuevo Header () obj sí lo hace

EnMDN Obtener

Hay este ejemplo:

 const myInit = { method: 'GET', headers: { 'Accept': 'image/jpeg' }, mode: 'cors', cache: 'default' }; let myRequest = new Request('flowers.jpg', myInit);

Puede ver que el objeto de los encabezados es solo un objeto literal normal, pero cuando lo intento, este código no agrega el encabezado personalizado:

 const PWA_FETCH_BYPASS = "X-PWA-Fetch-Bypass" let init = { headers: { PWA_FETCH_BYPASS: 'true' }, } let response = await fetch(url, init)

Pero este código agrega el encabezado personalizado:

 const PWA_FETCH_BYPASS = "X-PWA-Fetch-Bypass" let myHeaders = new Headers(); myHeaders.append(PWA_FETCH_BYPASS, 'true') const init = { headers: myHeaders } let response = await fetch(url, init)

¿Por qué la versión literal del objeto no agrega el encabezado personalizado?

about 4 years ago · Juan Pablo Isaza
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!