cors-anywhere: Missing required request header?

Demo says 200 OK for this but the API returns Missing required request header. Must specify one of: origin,x-requested-with Am I missing something?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

@burgerga Your “proper” way is in fact less efficient, because now you’re proxying twice:

  1. First through your own server (/scrape/).
  2. Then via your server to CORS Anywhere.

From the browser’s point of view, the initial request is same-origin, so it does not automatically include the Origin header. If you really want to keep the current two indirections, add the X-Requested-With: XMLHttpRequest request header, either in Angular’s HTTP client, or through the proxy config.

angular-cli uses webpack-dev-server under the hood, which in turn uses http-proxy-middleware, which in turn uses http-proxy (which is the same library that I use under the hood for proxying). According to the documentation, the request header can be set via the "headers" option.


Although you can achieve that desired behavior, I suggest to just rewrite the URL at the client side (in your Angular application). That is actually the proper place for this. This can be done automatically in Angular through a $http interceptor: see https://docs.angularjs.org/api/ng/provider/$httpProvider and https://docs.angularjs.org/api/ng/service/$http#interceptors