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
Request header field Time-Zone is not allowed by Access-Control-Allow-Headers in preflight response

I have a WEB API which I am consuming from POSTMAN, and it works perfectly fine:

Headers:

Content-Type:application/json X-Developer-Id:asdasdas X-Api-Key:asdasdas Authorization:Bearer sasdasdsa Time-Zone:Morocco Standard Time

When I do a GET request in POSTMAN it works fine, however from angular 2 (Ionic 2) I get the following error:

Request header field Time-Zone is not allowed by Access-Control-Allow-Headers in preflight response.


let params: URLSearchParams = new URLSearchParams();
        params.set('date', date);

        //Header
        let headers = new Headers({
            'Content-Type': AppSettings.ContentType,
            'X-Developer-Id': AppSettings.XDeveloperId,
            'X-Api-Key': AppSettings.XApiKey,
            'Time-Zone': AppSettings.time_zone,
            'Authorization': AppSettings.Authorization + localStorage.getItem("AccessToken")
        });

        var RequestOptions: RequestOptionsArgs = {
            url: AppSettings.UrlAvailability + userId,
            method: 'GET',
            search: params,            
            headers: headers,
            body: null
        };

        return this.http.get((AppSettings.UrlAvailability + userId), RequestOptions)
            .map(res => res.json())
            .do(data => { data },
            err => console.log('error: ' + err));

First I would think that the API developers have to do something on the server side, like enabling that Time-Zone Header on CORS, however if that would be the case then we would get the same error on POSTMAN, but it works fine there.

What am I missing here?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This is something you need to configure on the server. You first need to make sure you have CORS support. I don't use ASP.NET, so I don't know how to do it. I'm pretty sure a quick google search will find you the answer. Then you need to make sure in that server CORS config, that special headers you want the client to be able to send are added to the CORS allowed headers. That's what the error is saying: that the headers are not included in the response header Access-Control-Allow-Headers. The response header would look like

Access-Control-Allow-Headers: X-Developer-Id, X-Api-Key, Time-Zone, Authorization

To learn more about CORS, see the MDN

First I would think that the API developers have to do something on the server side, like enabling that Time-Zone Header on CORS, however if that would be the case then we would get the same error on POSTMAN, but it works fine there

No, Postman does not have the same restrictions. It is a native desktop app. Fun fact: 99% of people who post questions on SO that hava a CORS problem, have somewhere in their post "...but it work with Postman!". So don't feel bad :-)

over 4 years ago · Santiago Trujillo Denunciar

0

I think you should remove some of your headers and check you content-type so your request could be considered as a "simple request" and then won't trigger a CORS preflight as explained in the doc.

source: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#examples_of_access_control_scenarios

Apart from the headers automatically set by the user agent (for example, Connection, User-Agent, or the other headers defined in the Fetch spec as a forbidden header name), the only headers which are allowed to be manually set are those which the Fetch spec defines as a CORS-safelisted request-header, which are:

  1. Accept
  2. Accept-Language
  3. Content-Language
  4. Content-Type (please note the additional requirements below)
over 4 years ago · Santiago Trujillo 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