Access Control Request Headers, is added to header in AJAX request with jQuery

前端 未结 6 1426
不知归路
不知归路 2020-11-22 10:29

I would like to add a custom header to an AJAX POST request from jQuery.

I have tried this:

$.ajax({
    type: \'POST\',
    url: url,
    headers:          


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 11:04

    And that is why you can't create a bot with JavaScript, because your options are limited to what the browser allows you to do. You can't just order a browser that follows the CORS policy, which most browsers follow, to send random requests to other origins and allow you to get the response that simply!

    Additionally, if you tried to edit some request headers manually, like origin-header from the developers tools that come with the browsers, the browser will refuse your edit and may send a preflight OPTIONS request.

提交回复
热议问题