带有POST请求的Angular Service Worker [英] Angular Service Worker with POST request
问题描述
我将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:
https://randomuser.me/api/?results=20 --->可以,
https://test.moodlecloud.com/webservice/rest/server.php - ->是KO
I try to cache this two URLs : https://randomuser.me/api/?results=20 ---> It's OK https://test.moodlecloud.com/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.
这篇关于带有POST请求的Angular Service Worker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!