0

I need to perform a get and got this error from console

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

This is what I have for the header:

Access-Control-Request-Headers:accept, authorization, client_id

I would like to remove client_id from the request header for this one call and not affect the global settings.

Here is the code:

    $http.get(url,{
      headers: {"client_id": undefined }
    })
      .success(function (geoData) {
        d.resolve(geoData);
      })
      .error(function (err, status) {
        d.reject(err);
      });

But it has no effect. What am I missing?

1 Answer 1

1

This error raised by CORS problem. Read here for more infor about prelighted request. You need config your server to handle cos request to allow customer header parameter like 'client_id'. For example config value for Access-Control-Allow-Headers in your server:

'Access-Control-Allow-Headers' : 'client_id','Content-Type, Authorization, Content-Length,

For handle header one by one base on request, you need define condition to build your header. it should be:

// build your header dynamic based on condition of request
var headerConfig = null;
if ('your condition to have client_id') {
    headerConfig = {"client_id": undefined }
}
else {
   headerConfig = {};
}

// request with headerConfig
$http.get(url,{
  headers: headerConfig
})
  .success(function (geoData) {
    d.resolve(geoData);
  })
  .error(function (err, status) {
    d.reject(err);
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.