Ajax Authorization Request headers fails again and again

后端 未结 1 785
深忆病人
深忆病人 2021-02-09 21:33

I\'m working on a consumer for a self-made API and having serious difficulties with setting the Authorization header. I am using JQuery for the Ajax requests, b

相关标签:
1条回答
  • 2021-02-09 22:04

    Well I found out what the problem was. The self-made service sent this back to the client as a global header : "Access-Control-Allow-Headers" with only "Content-Type" in it.

    This way our clients not using an User Agent (browser) ignored these headers and just sent the header anyway. But the browser tried to optimize the request and said "It won't accept the Authorization header so I'll just cut it before sending." this way is the package is smaller and the service won't allow it anyway (although it did...)

    So just adding "Authorization" to the Access Control Allow Headers part of the service made my Javascript/JQuery/Ajax requests send the request header as normal!

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