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

448
Views
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 answers
Answer question

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 Report

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 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!