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

简介: 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:


image.png


take 300938 for example:


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


image.png


image.png


原因:


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.


相关文章
|
8天前
|
Java
java原生发送http请求
java原生发送http请求
|
15天前
|
网络协议 Linux iOS开发
推荐:实现RTSP/RTMP/HLS/HTTP协议的轻量级流媒体框架,支持大并发连接请求
推荐:实现RTSP/RTMP/HLS/HTTP协议的轻量级流媒体框架,支持大并发连接请求
38 1
|
1天前
|
安全 网络安全 开发工具
对象存储oss使用问题之flutter使用http库进行post请求文件上传返回400如何解决
《对象存储OSS操作报错合集》精选了用户在使用阿里云对象存储服务(OSS)过程中出现的各种常见及疑难报错情况,包括但不限于权限问题、上传下载异常、Bucket配置错误、网络连接问题、跨域资源共享(CORS)设定错误、数据一致性问题以及API调用失败等场景。为用户降低故障排查时间,确保OSS服务的稳定运行与高效利用。
14 1
|
27天前
|
JSON 前端开发 数据格式
糊涂工具类真是场景下请求http接口的案例
糊涂工具类真是场景下请求http接口的案例
21 0
|
27天前
|
数据采集 缓存 前端开发
http和https请求服务器的时候在请求头部分都带什么到服务器呢?
HTTP和HTTPS请求头基本结构相似,HTTPS多了一层SSL/TLS加密。常见请求头如Accept(指定内容类型)、Authorization(身份验证)、Cookie(会话跟踪)、User-Agent(标识用户代理)等。HTTPS特有的头包括Upgrade-Insecure-Requests(升级到HTTPS)、Strict-Transport-Security(强制使用HTTPS)、Sec-Fetch-*(安全策略)和X-Content-Type-Options、X-Frame-Options等(增强安全性)。实际应用中,请求头会根据需求和安全策略变化。
20 0
|
28天前
|
网络协议 网络安全 API
Qt 网络编程之美:探索 URL、HTTP、服务发现与请求响应
Qt 网络编程之美:探索 URL、HTTP、服务发现与请求响应
41 1
|
29天前
|
域名解析 Kubernetes Linux
Kubernetes 外部 HTTP 请求到达 Pod 容器的全过程
Kubernetes 外部 HTTP 请求到达 Pod 容器的全过程
35 4
|
1月前
|
前端开发
webpack如何设置devServer启动项目为https协议
webpack如何设置devServer启动项目为https协议
134 0
|
3月前
|
Web App开发 移动开发 JavaScript
Python网络编程(三),HTTP协议
Python网络编程(三),HTTP协议
60 0