使用ES6的fetch API读取数据时要注意的一个和cookie相关的坑

简介: 使用ES6的fetch API读取数据时要注意的一个和cookie相关的坑

When I am doing a test of comparison between Stateful and Stateless BSP application ( mentioned in blog Stateless and Stateful – Different behavior in application side ), I meet with a strange issue.


The conclusion is stateful BSP application will handle request sequentially. Suppose in client I send two request A and B to server. Request A takes 3 seconds to finish and B 2 seconds.image.pngThe request is sent via jQuery API.


It means for stateful application, I will observe the following timeline in Chrome network tab:


(1) the start time of both request are almost the same, since I send out two request in client code almost at the same time.


(2) even though the second request itself takes 2 seconds to finish, the total processing time for it is 3 seconds waiting for A to finish first + 2 seconds = 5 seconds in the end.image.pngthe testing request for stateful application looks as below this time:

image.pngimage.pngThrough comparison I get to know that the session cookie

sap-contextid is not sent together with request triggered by ES6 Fetch API.

Then in Fetch documentation I find out that I need to add option credentials: “include”.

image.png




image.png

相关文章
|
14天前
|
SQL 关系型数据库 API
从API获取数据并将其插入到PostgreSQL数据库:步骤解析
使用Python处理从API获取的数据并插入到PostgreSQL数据库:安装`psycopg2`,建立数据库连接,确保DataFrame与表结构匹配,然后使用`to_sql`方法将数据插入到已存在的表中。注意数据准备、权限设置、性能优化和安全处理。
|
3月前
|
JSON 搜索推荐 API
【2024更新】如何使用google index api来自动提交url
本文提供了一个详细的指南,说明如何创建并使用使用google index api,google自动提交url来优化seo。
50 0
|
4月前
|
JavaScript Java Serverless
函数计算中,这里是用的curl的方式,如何改用http的post方式请求?还有如何设置oss打包的zip的保存目录?
函数计算中,这里是用的curl的方式,如何改用http的post方式请求?还有如何设置oss打包的zip的保存目录?
161 0
|
6月前
|
JSON API 数据格式
python使用POST方法从API获取数据
使用POST方法从API获取数据
|
JSON 缓存 前端开发
【并发技术系列】「Web请求读取系列」如何构建一个可重复读取的Request的流机制
【并发技术系列】「Web请求读取系列」如何构建一个可重复读取的Request的流机制
208 0
【并发技术系列】「Web请求读取系列」如何构建一个可重复读取的Request的流机制
|
JSON 网络安全 数据格式
requests库常用到的7个主要方法及控制访问参数
requests库常用到的7个主要方法及控制访问参数
132 0
|
网络协议 Python
Python模块requests测试接口时通过session传递
在测试接口时需要有些接口登录后方可操作,这时需要将登录的session进行传递,可以直接获取登录后的cookie,也可以使用requests.Session():
|
Web App开发 存储 缓存
Cookie 和 Storage API 区别与详解
Cookie 和 Storage API 区别与详解
163 0
Cookie 和 Storage API 区别与详解