Ajax request: Refused to set unsafe header

前端 未结 1 1215
耶瑟儿~
耶瑟儿~ 2021-02-05 04:40

I am trying to play an audio using Google Text-To-Speech. Therefore I need to post a request to their endpoint with the Referer and the User-Agent properly set. This call should

1条回答
  •  醉梦人生
    2021-02-05 05:07

    You can't. It is impossible.

    The specification requires that the browser abort the setRequestHeader method if you try to set those headers.

    If you need to set those headers then you'll need to make the request from your server and not your visitor's browser.

    (That said, if you need to be deceptive about the user agent or referer then you are probably trying to use the service in a fashion that the owner of it does not want, so you should respect that and stop trying).

    Also check the "Fetch forbidden header names".

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