带有POST请求的Angular Service Worker

编程入门 行业动态 更新时间:2024-10-10 15:20:24
本文介绍了带有POST请求的Angular Service Worker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将Angular 5.2.7与Angular Service Worker 5.2.7一起使用。

I use Angular 5.2.7 with Angular Service Worker 5.2.7.

我想缓存Web服务调用。因此,我在ngsw-config.json中有了此配置,用于dataGroups:

I want to cache webservices calls. So, I've got with this config in my ngsw-config.json, for dataGroups :

"dataGroups": [{ "name": "tasks-users-api", "urls": ["/api", "/rest"], "cacheConfig": { "strategy": "freshness", "maxSize": 20000, "maxAge": "1h", "timeout": "5s" } }]

我尝试缓存这两个URL: randomuser.me/api/?results=20 --->可以, test.moodlecloud/webservice/rest/server.php - ->是KO

I try to cache this two URLs : randomuser.me/api/?results=20 ---> It's OK test.moodlecloud/webservice/rest/server.php ---> It's KO

第一个按预期方式被缓存。这是一个简单的GET服务。 第二个不是。

The first one is cached as expected. It's a simple GET service. The second one isn't. It's a POST service with a form data sent as payload.

任何有关此问题的想法吗?

Any idea of what is wrong with that ?

推荐答案

服务工作者API 不允许POST / PUT请求。

Service Worker API does not allow POST/PUT requests.

在此博客文章展示了一个示例,说明了如何使用Indexed Db(如Roman Gherta的建议)来存储POST / PUT请求。

In this blog article it is showed an example on how you can use Indexed Db (as suggested by Roman Gherta) to store POST/PUT requests.

在 Mozilla资源上也建议使用此解决方案。

更多推荐

带有POST请求的Angular Service Worker

本文发布于:2023-10-12 04:24:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483713.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Angular   POST   Worker   Service

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!