How to pass headers for an XMLHttpRequest request

后端 未结 1 885
一生所求
一生所求 2021-01-28 02:29

I have an api which requires few headers to passed to get the response.Below is the working postman

Now Iam doing an http call to consume this and below is the

相关标签:
1条回答
  • 2021-01-28 03:10

    The MDN page for XMLHttpRequest.setRequestHeader() states:

    For your custom fields, you may encounter "not allowed by Access-Control-Allow-Headers in preflight response" exception when you send request to cross domain. In this situation, you need set "Access-Control-Allow-Headers" in your response header at server side.

    In your case, the X-Rundeck-Auth-Token header is such a custom header, and therefore this header must be listed in the Access-Control-Allow-Headers response header from the server, otherwise you'll get an error as above and the request will fail.

    Accept, Accept-Language, Content-Type, Content-Length are whitelisted headers that can be set without specifying them in the Access-Control-Allow-Headers header; there's also a list of request headers that can never be set, even if they are listed.

    0 讨论(0)
提交回复
热议问题