【发布时间】:2021-04-19 06:42:24
【问题描述】:
发件人:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests
以下是一个将被预检的请求示例:
const xhr = new XMLHttpRequest(); xhr.open('POST', 'https://bar.other/resources/post-here/'); xhr.setRequestHeader('X-PINGOTHER', 'pingpong'); xhr.setRequestHeader('Content-Type', 'application/xml'); xhr.onreadystatechange = handler; xhr.send('<person><name>Arun</name></person>');上面的示例创建了一个 XML 正文以与
POST请求一起发送。 此外,还设置了非标准 HTTPX-PINGOTHER请求标头。这样的 标头不是 HTTP/1.1 的一部分,但通常对 Web 有用 应用程序。由于请求使用了Content-Typeapplication/xml,并且由于设置了自定义标头,因此此请求是 预检。
如果请求同源但不遵循标头指南,是否会触发预检请求?
【问题讨论】:
标签: javascript html browser cors