预检请求无法使用访存API调用带有keepalive的POST请求 [英] Preflight request failing on calling a POST request with keepalive using fetch api
本文介绍了预检请求无法使用访存API调用带有keepalive的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用启用了keepalive
的访存api调用POST请求时,出现错误Preflight request for request with keepalive specified is currently not supported
.任何帮助,将不胜感激 .我正在beforeunload
事件上调用此api.
I am getting an error Preflight request for request with keepalive specified is currently not supported
on calling a POST request using the fetch api with keepalive
enabled. Any help would be appreciated . I am calling this api on beforeunload
event.
API请求
fetch(uri, {
method: 'POST',
headers: {
'Content-type': options.headers.get('content-type'),
'Authorization': options.headers.get('authorization')
},
body: JSON.stringify(interactionBody),
keepalive: true
}).catch((e) => {
console.log(e);
});
推荐答案
我找到了一种解决方法,直到 Chrome问题已解决
I found a workaround until the Chrome issue fixed
在使用mode: 'same-origin'
fetch(uri, {
method: 'POST',
headers: {
'Content-type': options.headers.get('content-type'),
'Authorization': options.headers.get('authorization')
},
body: JSON.stringify(interactionBody),
mode: 'same-origin',
keepalive: true
})
这篇关于预检请求无法使用访存API调用带有keepalive的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文