欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

SAP Spartacus产品数据HTTP GET请求前的OPTIONS请求

发布时间:2023/12/19 编程问答 32 豆豆
生活随笔 收集整理的这篇文章主要介绍了 SAP Spartacus产品数据HTTP GET请求前的OPTIONS请求 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

for every product displayed in the page, there is dedicated HTTP request to fetch data from backend via restful API:

take 300938 for example:

I see two http requests which are exactly the same, one with HTTP OPTIONS and one with HTTP GET.



原因:

Preflighted requests

Unlike simple requests (discussed above), “preflighted” requests first send an HTTP OPTIONS request header to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a request is preflighted if:

  • It uses methods other than GET or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML payload to the server using application/xml or text/xml, then the request is preflighted.
  • It sets custom headers in the request (e.g. the request uses a header such as X-PINGOTHER)

这个机制的必要性:Remember that by adding CORS, you’re potentially accepting requests from anyone, in which they could manipulate data on your server through requests (POST, PUT, DELETE etc). In these situations, like when using custom headers, the browser is just checking with the server first that the server is willing to accept the request before sending it as sending unsolicited requests to the server could be really dangerous for your data, and also, what’s the point in the browser sending potentially large payloads if the server isn’t wanting to accept them, hence the pre-flight OPTIONS check.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

总结

以上是生活随笔为你收集整理的SAP Spartacus产品数据HTTP GET请求前的OPTIONS请求的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。