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

210
Vistas
Tell fetch() to not send a Content-Type header at all

Is there a way to send an HTTP request with fetch() and tell it to not automatically set a header? I'm trying to get it to send a request without a Content-Type, I can get it to send an empty header

Content-Type: 

like this

fetch('http://localhost:8000/', {
  method: 'POST',
  headers: {
    'Content-Type': ''
  },
  body: 'some data'
});

but can I get it to not include the line at all?

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

0

Per step 36 of https://fetch.spec.whatwg.org/#dom-request and https://fetch.spec.whatwg.org/#concept-bodyinit-extract, a fetch-initiated request with a request body will always end up with a Content-Type header — because there are only two possible paths a request with a request body can take in the spec:

  1. If you don’t specify any Content-Type header at all in your fetch call, then the browser always automatically on its own sets a Content-Type header for the request; unless…
  2. If you specify a Content-Type header in your fetch call, then the browser uses the value you set.

So because those two are the only possible outcomes and because the fetch API doesn’t provide any method for completely removing any browser-set request headers, then if a request has a request body, there’s no way to send the request using the fetch API without it ending up with a Content-Type header.

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