search

Home  >  Q&A  >  body text

javascript - js cross-domain request error: Refused to set unsafe header "Referer"?

Try to use cross-domain request for data from another website in my website program. The target website needs to verify the refer parameter in the http request.

Turn on the cross-domain option of the chrome browser, and use the following style code to try to send a request

 $.ajax({
            headers: {
                "Referer":"https://xxx.com/xxxxxx"
            },
            type:'POST',
            data:{...},
            success:function(r){...}
 });

As a result, the browser reported an error: Refused to set unsafe header "Referer"

After querying the information, it seems that the browser does not allow setting the header parameters of the request.

Students with relevant development experience, please give me some advice. Is this requirement theoretically achievable? How to achieve?

phpcn_u1582phpcn_u15822703 days ago3195

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-07-05 10:44:13

    For security reasons, there are some restrictions on cross-domain XHR objects:

    • Cannot use setRequestHeader() to set custom headers

    • Cannot send and receive cookies

    • Calling the getAllResponseHeaders() method always returns an empty string

    reply
    0
  • 漂亮男人

    漂亮男人2017-07-05 10:44:13

    I just encountered it recently. You can refer to my article. If you don’t understand, you can ask me: /a/11...

    reply
    0
  • Cancelreply