SAP

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

2020-11-28  本文已影响0人  _扫地僧_

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:

这个机制的必要性: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.

上一篇下一篇

猜你喜欢

热点阅读