Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

457
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda